1
I am developing a simple game in which whenever an object exits the screen a variable of name score gets +1.
The idea is simple, what I am trying to do is to print the value of the variable score whenever the player scores 10 new points, that is, whenever the variable score receives the value of itself +10 is printed the value of the variable.
To do this I declared a variable called x that receives the same score value, if x equals 10 the score value is printed. Once the score value is printed, x returns to 0, and the idea is to repeat this over and over again.
The problem is that after printing score and the variable x is reset, x will receive the score value again and nothing will be printed on the screen anymore, as x will not be receiving 0 at all.
How can I fix this? I hope I’ve been clear!
CODE
Object:
public int x;
void Start() {
}
void Update() {
}
void OnBecameInvisible() {
Score.score += 1;
x = Score.score;
if (x == 10)
{
Debug.Log("VALOR DE SCORE: " + Score.score);
x = 0;
}
}
Score:
public static int score;
public Text score_txt;
void Start() {
score = 0;
}
void Update () {
score_txt.text = score.ToString();
}