Gameplay flow

Hi,

Maybe this has been talked about, but i can’t find an answer.

I’m working on a simple game. This game involves a gameplay with 2 objects and they can score goals. Sort of like Pong.

When the player has scored, i want to wait some time, display some info and then reset some stuff to start playing again.

My goal scoring mechanism is detected by collision, as this is called every frame, you don’t want your score updated X times.
So you’d want to detect the collision, update the score, wait, show some text, reset some stuff, begin again.

I don’t need code, but some pointers on how to do this with Unity, what’s the best approach to create such a flow. Can’t find it in the manual.

I’ve tried some stuff with WaitForSeconds, but that feels really ugly.

I’ve found something new. To wait some time and then reset some stuff in a function, i now use:

Invoke(MyResetFunction, sec)

Is this a good approach?

This may help:

file://localhost/Applications/Unity/Unity.app/Contents/Documentation/Documentation/ScriptReference/index.Coroutines_26_Yield.html

I would typically use something like:

// do something
yield WaitForSeconds(5.0); // wait for 5 seconds
// do something more...

I’m not sure about it looking ugly, I think its kinda pretty.

Also, you may not be able to yield in physics callbacks like OnCollisionEnter. I am not positive on that though. I do know you can’t call it from Awake. Just call a different function and let that function yield if you run into that problem.