- Home /
OnTriggerEnter() not working
I have created a script that will destroy an object when it enters a collider and instantiate another object at a spawnpoint. The only thing is that the none of the events inside the OnTriggerEnter class are going ahead.
Here is my script:
using UnityEngine;
using System.Collections;
public class Destroy : MonoBehaviour {
public bool _spawning = false;
public void OnTriggerEnter(Collider other){
_spawning = true;
Destroy(other);
GameObject _spawner;
Spawner _spawnScript;
_spawner = GameObject.Find("SkirtingSpawner");
_spawnScript = _spawner.GetComponent<Spawner>();
_spawnScript.Spawn();
}
}
I have received no errors and cannot understand why this is not working
Answer by Finnigan · Mar 30, 2015 at 10:28 PM
First make sure the trigger is working by showing a message, something like
Debug.Log(other.name+" colliding with "+name);
If it doesn't print anything on the console then make sure the collider has the Trigger option checked.
If that doesn't work neither then make sure the layers of those objects are collidable between themselves.
I get no messages in the console with this. I also checked and the object the script is applied to has the collider ticked to be a trigger.