Hi,
I have been trying to make some code so that when you collide with an enemy, text pops up saying “Dead”
The enemy class finds that you’re dead and then is supposed to send a message to the text class (called Dead) to run its function (called Death) I have no errors and it prints out “collide” when I hit an object. It doesn’t have an error when I collide, it just doesn’t send the message.
Enemy code:
var Health = 100;
var Player : GameObject;
function Update ()
{
transform.Translate(0, 0, Time.deltaTime);
if(Health <= 0)
{
Dead();
}
}
function ApplyDamage (TheDamage : int)
{
Health -= TheDamage;
}
function Dead()
{
Destroy (gameObject);
}
function OnCollisionEnter (col : Collision)
{
if(col.gameObject.name == "Player")
{
Debug.Log ("colision");
gameObject.SendMessage("Death");
//Destroy (col.gameObject);
}
else if(col.gameObject.name == "Ball")
{
Destroy (gameObject);
}
}
Death code:
#pragma strict
function Start () {
}
function Update () {
}
function Death ()
{
Debug.Log ("Dead");
GetComponent(MeshRenderer).enabled = true;
}
Any and all help is appreciated.