- Home /
How can I detect a collision with a tagged game object?
I need to know how to detect a collision between the character controller and a tagged game object, (the zombie). This is my code attached to the character controller, I don't know what I'm doing wrong. I am only 15, so it is probably something really stupid, but thanks for your help.
#pragma strict
var playerHealth : int = 100;
var style : GUIStyle;
function Start ()
{
playerHealth = 100;
}
function Update ()
{
if(playerHealth < 1)
{
Application.LoadLevel("Game Over");
}
}
function OnCollisionEnter (collision : Collision)
{
if(collision.gameObject.tag == "Zombie")
{
print("Zombie Collision Detected");
playerHealth -= 10;
}
}
function OnGUI ()
{
GUI.Label (Rect (75,725,100,100), playerHealth.ToString(), style);
}
//Thanks for your help!
Comment
Answer by Nase770 · Jun 03, 2014 at 03:42 AM
It didn't work, thanks for the answer, though. Just so people know, the zombie IS tagged.