pausing csharp function mid way through?

Is this possible… Or do we need to set it up differently?

void SomeFunction (){
// store a position here

WaitForSeconds (1.0)

// store the new position here
// do equation with two stored position
}

I am getting an error on the ‘WaitForSeconds’ line…

Thanks…

In order to wait, your functions must be IEnumerators and must yield

http://docs.unity3d.com/412/Documentation/ScriptReference/index.Coroutines_26_Yield.html

Ok thanks… So if I yield return I pass back to the calling script? Does what follow still get calculated in the yielded script?

Thanks

Edit, the link was great… it does carry on :slight_smile:

yield return new WaitForSeconds (Time);

No errors thus far, got to clean up the caller and we’ll see :smile:

Just thought I would mention invoke here…e.g.

void DoThis()
{
//grab position do equation
}

and then in code somewhere tell ti to execute in the future…

Invoke(“DoThis”. 1.0);

Invoke often results in simpler and easier to maintain code, IMHO

I am really struggling with this…

Please, how would I need to structure it regarding my OP?

Thanks all

I can post the code I have If you want a good laugh :smile:

I didn’t realise I could call it with ‘Start coroutine’ :smile: All sorted

HorizontalVelocity = Velocity * Mathf.Cos (Angle);

Is the only thing giving me an issue now…

I am using .linq

I have a .Sin version working alongside it, and I’m calculating the angle… both of these in play test debug are producing good results, within the range of ± I’d expect…

But that Cosine… Is all over the place… one moment its, 22, next time, -7, next time 12…

Have I done something wrong with that code snippet please

Thanks all

As far as I can debug… The Velocity and Angle are stable, so I cant understand the flawed results of Horizontal velocity… (?)