- Home /
Help using trigger - My item won't be destroyed and I keep going through it
Help! I am trying to collect an object and I just keep going through it without it being destroyed
C#
using UnityEngine; using System.Collections;
public class powerCell : MonoBehaviour {
public float rotationSpeed = 100.0f; void Update () { transform.Rotate (new Vector3(0,rotationSpeed * Time.deltaTime, 0)); } void OnTriggerEnter(Collider other) { if(other.gameObject.tag == "First Person Controller") { other.gameObject.SendMessage("CellPickup"); Destroy(other.gameObject); }
}
}
What am I doing wrong?? Thanks!!!
Answer by Linus · Jul 07, 2012 at 12:57 AM
Your code looks fine to me.
Make sure one of the objects has a rigidbody From http://docs.unity3d.com/Documentation/ScriptReference/Collider.OnTriggerEnter.html Note that trigger events are only sent if one of the colliders also has a rigidbody attached.
Is the isTrigger set Make sure the isTrigger check box is in fact checked on the collider component.
z position If this is a 2d style game. Make sure the depth (usually z) is in the right position
Recheck Collider Size