Quantcast
Channel: Latest Questions on Unity Answers
Viewing all articles
Browse latest Browse all 171066

How does a "for" loop behave in unity?

$
0
0
I am trying to iterate through each element of an array in the Update function(so every time the Update function is called, every element of the array gets modified). I used a "for" loop. As a result it does not work as I expected. For example if I have the segment of code below in the Update function,I expect to get output 0~19, 3 is followed by "j is 3 now.",each other number is followed by "j is not 3 now.", but I only get 0~19, 0 is followed by "j is not 3 now", 3 is followed by "j is 3 now", and nothing for other numbers. It seems each case will only be executed once. I tried to move the loop out of Update function in a new defined function, it won't help. Could anyone tell me why? Thanks. for(int j=0; j<20; j++){ print(j); if(j==3){ print("j is 3 now."); }else{ print("j is not 3 now."); } }

Viewing all articles
Browse latest Browse all 171066

Latest Images

Trending Articles



Latest Images