hi every one
i’m a beginner and it’s my first game .
when player collides with gameobject that you see in the picture the elevator that is a plane object moves up but not much for example 2 units (i want y axis of them to be 2).
the problem is that ,the transform.position and transform.translate works out side the for loop but not inside it .
thanks dude ,I remember I did the same mistake in the past and some one explained me why it can’t equal 4 , but I can’t remember why !
can you explain it for me ,please
for loops are a shorthand. When you write a for loop that looks like:
for (A;B;C) {
body
}
What the compiler actually sees is more like:
A is executed before anything else
loop:
if B is true, then the body is executed; if it’s not, break out of the loop
execute C
go back to loop
If you step through your code loop by loop, you can see that i is set to 1, and then it compares (i == 4) which comes out to false, so it immediately breaks out of the loop.
When Unity freezes like that, that almost always means you’ve created an infinite loop. In my example above, that means that B is always coming up as true. If you step through it loop by loop, you should be able to see that i is being re-set every time the loop runs to Time.deltaTime, so it never reaches 4. So, it loops forever. To fix that issue, you’ll want to remove i=Time.deltaTime
But, looking at the function, I think you probably don’t want that loop there at all. I’m trying to guess what your function is supposed to do - is it supposed to move the thing forward as long as it overlaps the player?