hey everyone, i have been trying to get this to work but just gave up. please help
I need a GUI health bar that would lower when the enemy object hits me
this is for my player
var curHealth=100.0;
function TakeDamage(amount : float){
curHealth-=amount;
if(curHealth <= 0.0){
Destroy(gameObject);
}
}
this is for my enemy to give damage to my player
var damage : float=5.0;
private var lastPosition : Vector3;
function OnEnable () {
lastPosition=transform.position;
}
function LateUpdate(){
var hit : RaycastHit;
var ray : Ray=Ray(lastPosition, transform.position - lastPosition);
var dist = Vector3.Distance(transform.position, lastPosition);
if(Physics.Raycast(ray, hit, dist)){
hit.collider.gameObject.SendMessage("TakeDamage", damage, SendMessageOptions.DontRequireReceiver);
Destroy(gameObject);
}
lastPosition=transform.position;
}