why this loop go to fast .... please help

hi …
i have this code working … but
Too fast, very very fast.

i just need a texture to be intermittent, one second on then off then on then off …etc
35 times.

but never stop, and go to fast … very very fast intermitent.

here is my code ( .js )

var arrow_01: GameObject;

function Update () {
   
intermitente();

                               
}

function intermitente () {    
   

    yield WaitForSeconds (0.3);
    for(var i : int = 0; i > 35; i++)

    arrow_01.SetActive (true);
    yield WaitForSeconds (1.1);   
    arrow_01.SetActive (false);
    yield WaitForSeconds (1.2);   
   
}

if i use function Start ()
just work ones and no more.

any help will pareciate so much
thanks

Well, you’re calling it from update which means you have 1 per frame of your function running. If you have 60fps that means you have 60 intermitente running per second, so they will all trigger like crazy after each other.

I think your for loop is missing brackets. Fix that and move the call back to start. should fix it.

function intermitente () { 
 
    yield WaitForSeconds (0.3);
    for(var i : int = 0; i > 35; i++)
   {
    arrow_01.SetActive (true);
    yield WaitForSeconds (1.1);
    arrow_01.SetActive (false);
    yield WaitForSeconds (1.2);
   }
}

Also just a friendly note, UnityScript is going out the door, consider switching to c#. It will be easier to help you as well for the future.

2 Likes

In addition to what @Brathnann said…

for(var i : int = 0; i > 35; i++)

This loop will never execute. The code says “start i at 0. while i > 35 execute the loop, then increment i.” Since i starts out at 0 it is never greater than 35, so the loop exits immediately. What you most likely want is:

for (var i: int = 0; i < 35; i++)

Ah, yep. that also. Didn’t look that close at the loop itself. So yes, that as well @iTextures . The reason your code runs right now is because you are missing the brackets, adding the brackets would have made the loop not run, but @Dave-Carlile has the other fix you need for that.

1 Like

thanks you … thanks you a lot
I am … but this script i really need it … but i am change to c# since 2 month … tryi9ng to make my new game all with c# … vido here
.

https://www.youtube.com/watch?v=_4VwNPdq-CE

1 Like

thansk so much … really apreciate so much all your help …
:slight_smile: