- Home /
Question by
BaldBadger · May 09, 2013 at 04:49 AM ·
collisiondestroyontriggerenterdebug
OnTriggerEnter issue
function OnTriggerEnter (col : Collider) {
if(col.gameObject.tag == "Spell")
{
Debug.Log("Hit");
Destroy(this.gameObject);
}
}
Every time I set that up, and every time I send an object that is tagger appropriately, nothing happens. Not even the Debug.... can anybody tell me what I'm doing wrong?
Comment
try to put the Debug outside the if statement, if it appears then check that your object is tagged.
Also check that the script is on the right object .
Best Answer
Answer by SubatomicHero · May 09, 2013 at 07:53 AM
try altering the if statement to:
if (col.gameObject.transform.tag == "Spell")
{
Debug.Log("Hit");
Destroy(this.gameObject);
}
Also worth double checking the tag is "Spell" and not "spell" or some variation
You could also remove the if statement and debug ANY object that enters the trigger. You can then use the tag in the debug to do what you want like so:
function OnTriggerEnter(col : Collider)
{
Debug.Log(col.gameObject.transform.tag);
Debug.Log(col.gameObject.transform.name);
}