- Home /
Power-Ups scripting error
Hey,
I'm currently working on a space shooter and I'm starting to add power-ups to it. I had a power-up that gave you an extra life but then i switched from lives to health and I'm having a bit of trouble. I'm sort of familiar with If statements but not sure how to format them using Javascript. I want to be able to add 50 health if the players health is below 50 points, and if their health is at 50 or above i want to just make their health an even 100.
Here's what I have:
(Scripts Below)
I also tried doing a If/Else statement but I also wasn't sure how to do that. Any help is appreciated and if I'm doing it completely wrong then just say so! :P
Thanks.
$$anonymous$$y script got cut off up there so here's what I have.
function OnTriggerEnter(otherObject: Collider){
if(otherObject.gameObject.tag == "bonus1" && playerLives <= 50){
playerLives += 50;
Destroy(otherObject.gameObject);
}
if(otherObject.gameObject.tag == "bonus1" && playerLives >= 50){
playerLives == 100;
Destroy(otherObject.gameObject);
}
Answer by PurpleHeartGames · Jun 19, 2011 at 03:05 PM
function OnTriggerEnter(otherObject : Collider){
if(otherObject.gameObject.tag == "bonus1" && playerLives < 50){
Destroy(otherObject.gameObject);
playerLives += 50;
}
else if(otherObject.gameObject.tag == "bonus1" && playerLives >= 50){
Destroy(otherObject.gameObject);
playerLives = 100;
}
}
That should do it, I tested it and it works on my part.
$$anonymous$$ore common is to put the "what is it" check 1st, then what to do: if(tag==bonus) { if(hp<50) add50 else be100 }
Your answer
Follow this Question
Related Questions
Why does if(levelToLoad ==null) not work? 2 Answers
If/else statements working one way, and not the other 0 Answers
Setting Scroll View Width GUILayout 1 Answer
not sure whats happened :S 1 Answer
Code not entering if statement. 1 Answer