- Home /
why is OnTriggerEnter Destroy working once then stoping?
i have a very simple script whose whole job is to destroy any object that enters this collider Trigger. all objects are slowly moving towards collider. it works perfectly for the first object but ignores all objects that follow. i thought i might have had settings different on the other objects so i duplicated a couple of the first object that works fine and still they fail to get deleted.
void OnTriggerEnter(Collider other)
{
Destroy(other.gameObject);
}
this script is attached to a floating box with the box collider set to trigger and gravity turned off on its rigid body, any help you guys can give me about why this is doing this would be helpful.
(side note i added a Debug.Log to the start of OnTriggerEnter to see if it was even noticing the other objects entering and it only ran once when the first object goes into it)
after a bit of fiddling a believe the issue is related to my move script. the first object is located right on the edge of the collider trigger. once i moved the first object further away from the destroyer it too would fail to be deleted.
here is the move script using UnityEngine; using System.Collections; public class $$anonymous$$ovementScript : $$anonymous$$onoBehaviour { public float playerSpeed = 10.0f; // how fast the player is moving public Vector3 moveDirection = Vector3.forward; // what direction the player is moving // Use this for initialization void Start () { } // Update is called once per frame void Update () { transform.Translate(moveDirection * playerSpeed * Time.deltaTime); } } i don't however fully understand how this is preventing the object from being deleted.