Im having a “Lava” Cube, and attached a Hurt script to that, so that the player will get hurt.
My Character Controller have a Rigidbody.
So thats the Script:
#pragma strict
public var health : float = 100.0;
public var damage : float = 20.0;
function Start () {
}
function Update () {
}
function OnTriggerStay (otherObj : Collider) {
if (otherObj.tag == "Player"){
DeductHealth();
}
if ( health <= 0.0 )
{
Application.LoadLevel("gameover");
}
}
function DeductHealth () {
Debug.Log("Deducting Health!");
health -= damage * Time.deltaTime;
}
function OnGUI()
{
GUI.Box( Rect( (Screen.width * 0.5) - 60, Screen.height - 35, 120, 25 ), "Health : " + parseInt( health ).ToString() );
}
But if im going on the Lava, nothing happens?