I have tiempo -= Time.deltaTime;
and when it reaches 0 I want it to be replaced according to a variable that is being added, that is to say, i = 2
when time reaches 0, what tiempo = 2
, and then a tiempo = 3
... because there will be a i++
, but if I put it tiempo = i
or tiempo = +i
not it understands nothing and it doesn't take me i
, why? they are float
both.
code:
void Update(){
float tiempo,i=2;
tiempo -= Time.deltaTime;
i++;
if(tiempo == 0)
tiempo = i; // Esto no me coge que es i
}
Surely time is never 0 because
reduce that variable by fractions, use
Although user3175146 's answer is part of the problem, perhaps a very important one, I think that even so this doesn't do what you want, and maybe now you are going "crazy" without knowing why it doesn't work for you, or even worse, maybe you are not aware of it. It doesn't work as you describe in your question to the mess:
First case:
Second case (although the variables are improved to global):
Now even if you put them as global variables this will do things you don't want, because the update is called x times per frame, and
i
it increases in each update, so it is possible that time will take to be<= 0
y when it is allocated inside theif
.tiempo = i;
100 is assigned the same as 200, who knows, becausei
as said, it increases each time you enter the update, and you say something like this in the question ... when time reaches 0, what time = 2, and after a tiempo = 3... but we already saw that time may never go through 2 or three in the assignment, except the first time it enters the if or soI think this is what you are looking for:
Global variables initialize it in the
Start
for example and without minimizing what user3175146 mentioned because it is a very important part, note that you have to increase the valuei++
inside theif
bone when time is<=0
as user3175146 mentioned because what time it is== 0
is a lottery, so each time the time is up this will be assigned the value ofi++
Note: if you want it to increment first
i
before assigning it, then change the order inside theif
.