Print whenever variable receives a certain value

1

I'm developing a simple game where whenever an object exits the screen a variable named score gets +1.

The idea is simple, what I'm trying to do is to print the value of the variable variable whenever the player makes 10 new points, that is, whenever the variable score receives the value of itself +10, the value of the variable.

To do this I declare a variable named x that receives the same score value, if x is equal to 10 the score value is printed. Once the score value is printed, x returns to value 0, and the idea is to repeat this without stopping.

The problem is that after printing score and the variable x is zero, x returns the score value and nothing will be printed on the screen anymore, this is because x will not actually receive 0.

How can I fix this? I hope I have 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();
}
    
asked by anonymous 31.08.2018 / 18:45

1 answer

2

You do not need the variable x , you just need to validate if the rest of the entire division by 10 is 0 :

void OnBecameInvisible() 
{
    Score.score += 1;

    if ((Score.score % 10) == 0)
        Debug.Log("VALOR DE SCORE: " + Score.score);
}
    
31.08.2018 / 19:21