- Home /
This post is currently awaiting moderation. If you believe this to be in error, contact a system administrator.
Question by
DerpimusPrime · Oct 26, 2013 at 12:41 AM ·
triggerdestroy
Help with Destroy GameObject Code
I cant figure out why this code is destroying the object with the tag Zombie rather than the object the script is on.
#pragma strict
var health : float;
var BarrCooldown : boolean = false;
function Awake()
{
health = 5;
}
function Update()
{
if (health <= 0)
{
Destroy (gameObject);
}
}
function OnTriggerEnter(collision : Collider)
{
if(collision.gameObject.tag == "Zombie")
{
if (BarrCooldown == false)
{
health -= 1;
StartCooldown();
}
}
}
function StartCooldown()
{
BarrCooldown = true;
yield WaitForSeconds(3);
BarrCooldown = false;
}
Comment
Best Answer
Answer by clunk47 · Oct 26, 2013 at 12:47 AM
Don't use 'collider' as your Collider variable name, because 'collider' refers to the Collider component attached to your current GameObject. Try naming it col or other. Also, be sure you don't have this script attached to your "Zombie" GameObjects.
OnTriggerEnter(other : Collider)
Nothin. I changed it to "OnTriggerEnter(other : Collider)" and set "if(other.gameObject.tag == "Zombie")" and its still happening.
Be sure you don't have the script attached to the "Zombie" GOs.
You don't understand how infuriated I am right now. Thank you. Lol.
Your answer
