- Home /
Question by
KRUZAA · Mar 02, 2014 at 02:35 PM ·
2djavascriptguiscore
Pause When Score Reached?
I want to stop the game when the score reaches 10 but the code i have doesnt work. I have the score working and it counts up fine but nothing happens at the score 10
static var score : int = 0;
var guiScore : GUIText;
function Start () {
guiScore.text = "Green = 0";
}
var playerScore :int = 0;
var computerScore :int = 0;
private var scoreMax : int = 10;
function Update ()
{
if(score = 10)
{
pause.enabled = true;
Time.timeScale = 0;
Screen.showCursor = true;
}
}
function OnCollisionEnter2D(col : Collision2D){
if (col.collider.name == "GoalFieldG"){
score += 1;
guiScore.text = "Green = " + score;
print ("Point Scored");
}
}
Comment
Answer by SirCrazyNugget · Mar 02, 2014 at 03:01 PM
you need to use two equals for comparisons if(score == 10)
Answer by Calbbi · Mar 02, 2014 at 03:01 PM
I'm new to unity, but could it be that if(score = 10) needs to be if(score == 10)?