- Home /
How to write "if (var int = var int 2)" ?
Hello, I'm trying to create a counting effect on unity, There is my code
#pragma strict
static var Score : int = 0;
var fakescore : int = 0;
var scoreboard : GameObject;
function Update () {
if (scoreboard.active)
{
fakescore += 1;
}
if (gameObject.active)
{
var t : TextMesh = scoreboard.GetComponent(TextMesh);
t.text = fakescore.ToString();
gameObject.GetComponent("Timer (Script)").active = false;
if ( fakescore > Score){
t.text = Score.ToString();
}
}
}
so, I want to do this;
If fakescore equals Score, Set TextMesh to "Score.ToString();" but code didn't worked :( So can anyone help me ?
Answer by perchik · Sep 06, 2013 at 01:57 PM
in javascript:
var x :int =0;
var y:int =0;
if(x==y){ //do something }
The equal equal operator ==
compares if the two values are equal. A single equal =
actually assigns the value incorrectly.
So what you want to do is something like this f fakescore equals Score, Set TextMesh to "Score.ToString()
if(fakescore ==Score){
t.text = Score.ToString();
}
allright than, Double Equals :D I'll remember this Thanks !
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Pass a function(float) as variable 2 Answers
Displaying variable on UI text every frame (JS) 1 Answer
Current health may never exceed maximum health 2 Answers
Procedural Generation 1 Answer