Before I start, yes, I am new to Unity, and yes, I have looked at the FPS tutorial for help, as well as used google…
Im having some trouble with damage. When the player walks into a trigger (located in front of the enemy), they should lose 10 Health/2sec. My problem is that the player is not taking damage.
Here is the enemy damage script:
var damage : int = 10;
var DamageRate : int = 2;
private var enable : boolean = true;
function OnTriggerStay(col : Collider) {
if(col.gameObject.tag == "Player" && enable == true){
enable = false;
col.gameObject.BroadcastMessage("ApplyPDamage", damage);
yield WaitForSeconds(DamageRate);
enable = true;
}
}
And the player health script:
var health : int = 100;
var Player : Transform;
var Spawn : Transform;
var labelPos : Rect = Rect(20,10,300,50);
var Skin : GUISkin;
function Start () {
OnGUI ();
ApplyPDamage ();
}
function OnGUI () {
GUI.skin = Skin;
GUI.Label(labelPos, "Health: " + health + " / 100");
}
function ApplyPDamage () {
var damage : int;
health -= damage;
if(health <= 0) {
Die();
}
}
function Die () {
Player.position = Spawn.position;
}
Any help?
Thanks is advance, Geko_X
Thankyou!!! That had been getting to me for ages!!! Thankyou!
– Geko_X