C# wait for seconds variable

in C# how would i make the wait for seconds number a variable?

int num = 3;

yield return new WaitForSeconds(num);

is that what you mean?

yah i realized i was doing something wrong thanks still

Is there a way to make it a float"?

var whatAreYouTalkingAbout_sherlockturtle = new WaitForSeconds(524545.5635465464F);
yield return whatAreYouTalkingAbout_sherlockturtle;
1 Like

One other thing. var whatAreYouTalkingAbout_sherlockturtle is not directly a number. How would i takeaway from it ?

You wouldn’t. What you would do, is explain what you want to do, if you want help. :wink:

I want to take away the seconds that it waits. But im taking them away incremently by .5

I think your missing that he wanted c# meaning you have to call this in a co routine for it to actually wait.

void Start()
{
   StartCoroutine(Whatever() );
}

IEnumerator Whatever()
{
     float timeToWait = 5; 
     float incrementToRemove  = 0.5f;
     while(timeToWait > 0)
     {
          yield return new WaitForSeconds(incrementToRemove ); 
          timeToWait -= incrementToRemove;
     }
}

Then your thread is not related to coroutines. You just need to go read tutorials about working with numbers.

Why do you need the while loop?

Couldn’t you just do:

void Start()
{
   StartCoroutine(Whatever() );
}

IEnumerator Whatever()
{
     float timeToWait = 5; 
     yield return new WaitForSeconds(timeToWait); 
}
1 Like

Yeah, but he said he wanted to subtract time

→ I want to take away the seconds that it waits. But im taking them away incremently by .5

So maybe he wanted to use the time as a counter, So I gave an example that fits.

for your code i am getting errors

int num = 3;

Yield return new WaitForSeconds(num);
I am getting errors with the code. What else needs to go with it.
Please help me.
mindstormermage

It always helps if you actually post the errors. Also, the code with line numbers so people can see where the errors have occurred.