Hi, I'm trying to make a breakout clone using Javascript. There's an item that needs to add one extra life when the player collects it, but it's not incrementing right at all. It doesn't add one life during the current play session, but it adds one after I stop running the game and play again, as if incrementing how many lives the player should start the game with next time the game runs. It's hard to explain, but apparently somebody had the exact same problem six years ago: [UnityAnswers][1]
Here is my code, simplified:
//This script is attached to the item//
var ball:GameObject;
var paddle:GameObject;
function OnTriggerEnter (c:Collider) {
//I'd like either the ball or paddle to collect the item
if(c.gameObject.tag == "ball" || c.gameObject.tag == "paddle"){
ball.GetComponent(BallScript).balls++;
Destroy(gameObject);
}
}
.
//This script is attached to the ball//
var balls:int; //basically "lives"
function OnCollisionEnter(col:Collision){
if(col.gameObject.tag == "floor"){
balls--; //this works exactly how it should
ResetBall();
}
}
If anyone has had/solved this issue before, I'd really appreciate some help!
[1]: http://answers.unity3d.com/questions/26123/wow-unbelievable-variable-behavior-acts-static-whe.html
↧