Variable does not receive new value

0

I have an object that should be "falling" on the screen several times, and this works.

What I am trying to do is to have a variable named x receive 1 more each time this object passes the screen. When x receives another 5, I want another variable called and receive minus 1.

For this I declare both variables and assign a value to them: x = 0 and y = 5.

PROBLEM:

x should receive 1 more when the object passes through the screen, and this happens, but only once. When the object first passes through the screen, x receives 1 more, but after that, x to # 1 and receives nothing else.

Foryandminus1,xmustreceive5,soIthinkthat'swhyydoesnotchangethevalue,sincexisnomorethan1.

Noerrormessagesappearduringgameplay.

Whydoesnotthevalueofthevariablexchange?

CODE:

privateintx,y;voidStart(){x=0;y=5;}voidOnBecameInvisible(){//quandooobjetopassarpelatelax+=1;Debug.Log("Valor de x: " + x);

    if ((x % 5) == 0)
    {
        // sempre que x receber mais 5
        y -= 1;
        Debug.Log("Valor de y: " + y);
    }
}

Note: I did not put all the code because the rest of it is about the speed the object will drop, position and stuff like.

    
asked by anonymous 04.09.2018 / 01:27

1 answer

0

Try to change the name of the object that is passing on the screen every time you turn on the OnBecame function. It may be a possible solution. You can do the test by throwing two objects on the screen and observing if the variable X receives a sum.

    
28.09.2018 / 18:25