- Home /
Question by
vivek.rawat · Mar 07, 2014 at 05:53 PM ·
damagehealth
Need Help With Simple Player Health Damage Script
i m learning javascript from tutorials and have got myself in trouble please help me out
playerStatus
static var health : int = 100;
var points = int;
function update (){
}
if (health <= 0) {
kill();
}
function kill() {
print ("you are dead");
}
damage
var enter : boolean;
var damage = 10;
function Update () {
if(enter == true){
playerStatus.health -= damage;
}
}
function OnTriggerEnter (other : Collider){
if (other.gameObject.tag == "Player") {
enter = true;
}
}
function OnTriggerExit (other : Collider){
if (other.gameObject.tag == "Player") {
(enter) = false;
}
}
Comment
how do i make the amount of health show and how do i apply the damage.
Answer by perchik · Mar 07, 2014 at 05:54 PM
I formatted your code so that it's easier to read. Please click the 101 010 button next time.
Anyway, your problem is line 4 above, in playerstatus, you have a } which ends the update function but then try to do something after that. I think update should be Update also:
function Update (){
if (health <= 0) {
kill();
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613135633im_/https://answers.unity.com/themes/thub/images/avi.jpg)