This code does not work even with a box collider set to is trigger.What would be causing this? Code (CSharp): using UnityEngine; using System.Collections; public class DestroyCubes : MonoBehaviour { void OnCollisionEnter (Collision col) { if(col.gameObject.name == "prop_powerCube") { Destroy(col.gameObject); } } }
This script is attached to a cube with a box collider set to is trigger.A dynamic cube hits this cube and it should be destroyed.But nothing happens.
Triggers would call OnTriggerEnter, not OnCollisionEnter. Deselect "Is Trigger" if you want to use OnCollisionEnter.
Make sure "Is Trigger" is not selected...sometimes name can get a bit tricky, use gameObject.tag instead.
The colored cubes that fall had to have the script on them. while the cubes on the ground had to have the tag.Both cubes had to have rigid bodies and colliders not set to is trigger.I had it all mixed up.But i had not tried it with game object.name yet.