[SOLVED] OnTriggerEnter doesn't work?
I don't know why, but OnTriggerEnter doesn't work. I checked that one of my GameObjects has a rigidbody and that one of them has the right tag attached. However it still doesn't work. This is attached to other game objects (cubes).
public GameObject explosion;
void OnTriggerEnter(Collider other)
{
if(other.gameObject.CompareTag("Player"))
{
GameObject expl = Instantiate(explosion, other.transform.position, Quaternion.identity) as GameObject;
Destroy (gameObject);
Destroy(expl, 0.85f);
}
}
The next lines of code do work so I almost know for sure that the problem lies in the OnTriggerEnter or the tag. But this also makes my main character explode whenever it hits the terrain. This is attached to my main character
public GameObject explosion;
void OnCollisionEnter()
{
GameObject expl = Instantiate(explosion, transform.position, Quaternion.identity) as GameObject;
Destroy (gameObject);
Destroy (expl, 0.85f);
}
I appreciate it if you would take the time to help me :D
Comment
Best Answer
Answer by spooneystone · Feb 07, 2016 at 10:46 PM
Make sure you have the trigger box ticked on your collider in the inspector on the GameObject that this script is attached to.