[SOLVED]c# Scipt every second

Hi, I would like to create a script which runs somethind every odd and even seconds…
So the first second do x the 2nd second do y.
Any help apriciated. Thanks.

You can invoke a method every x seconds using InvokeRepeating()

1 Like

But if i do.

Invokerepeating("x",1f,2);

and

Invokerepeating("y",2f,2);

Will that work?

Without having tested it: yes

1 Like

Invokerepeating takes as argument name of the method to invoke as a string and so it has to then look it up and is generally slow, unsafe, bad and you shouldn’t use it. Also you set off this method to get invoked over and over again some where out there in space and you kind off loose track of your code flow. This is unelegant and makes debugging hard.

Use a Coroutine instead.

To be sure… you can always have them invoke eachother…

void Even(){
    //your code
     Invoke("Odd", 1.0f);
}

void Odd(){
     // your code
     Invoke("Even", 1.0f);
}

Thank you I finnaly solved it.