MonoEvent comes with 2 prebuilt coroutines for delaying, one of which is timescale independent.

MonoEvent comes with 2 prebuilt coroutines for delaying, one of which is timescale independent.

−

Create two more coroutines, '''MoveLeft()''' and '''MoveUp()'''. Configure them so that they move the quad to the left several units and up several units, respectively. Finally, using '''Delay''' and '''ScaledDelay''', change the return array of '''InitEvent()''' so that the coroutines are executed in the proper order. Note that since we changed the time scale, and that WaitForSeconds is time scale dependent, we need to adjust for this in the '''ChangeColorRandom''' coroutine:

+

Create two more coroutines, '''MoveLeft()''' and '''MoveUp()'''. Configure them so that they move the quad to the left several units and up several units, respectively. Finally, using '''Delay''' and '''ScaledDelay''', change the return array of '''InitEvent()''' so that the coroutines are executed in the proper order. Note that since we changed the time scale, and because WaitForSeconds is time scale dependent, we need to adjust for this in the '''ChangeColorRandom''' coroutine:

<syntaxhighlight lang="csharp">

<syntaxhighlight lang="csharp">

Revision as of 17:56, 4 June 2014

Contents

MonoEvent Primer

Initial Notes

This tutorial is NOT a Unity tutorial nor a primer to C# or programming in general. This tutorial assumes that you already have a good grasp of how Unity works and that you have intimate knowledge of programming concepts and the C# language.

BSGTools is C# ONLY. Unityscript and Boo are NOT supported.

MonoEvent was designed for programmers, by a programmer. It has limited configurable options in the Inspector, and the base script should not be manually added to a GameObject for any reason. Nearly all configuration is done in code.

Setting Up The Scene

The content of our scene is really simple:

A quad primitive, at (0,0,0)

An orthographic camera, at (0,0,-10)

A directional light, at (0,0,-10)

Creating The MonoEvent

Create a new script called EditQuadEvent and add it to the camera. Delete the default MonoBehaviour methods and make the base type MonoEvent. You're required to fully implement the base abstract class, and this involves overriding the InitEvent() method:

Creating The Initial Tasks

Our first goal is to change the quad's renderer's color to a random color multiple times with delays in-between. Add serialized private renderer field so that we can assign this in the inspector. Also, create a new coroutine method called ChangeColorRandom(), with a return type of IEnumerator:

Return to Unity, and enable the option titled "Execute On Start". Now run your scene to see the quad change colors.

Delays And Additional Tasks

Set your projects time scale to a value of (0.5).

Our next goal is to have our event do the following:

Change the color of the quad multiple times with delays in-between.

Wait for 0.5 second, independent from time scale.

Move our quad over several units to the left (-x).

Wait for 0.5 second, affected by time scale.

Move our quad several units up (+y).

Execute one more half-second, time scale independent delay and then loop.

MonoEvent comes with 2 prebuilt coroutines for delaying, one of which is timescale independent.

Create two more coroutines, MoveLeft() and MoveUp(). Configure them so that they move the quad to the left several units and up several units, respectively. Finally, using Delay and ScaledDelay, change the return array of InitEvent() so that the coroutines are executed in the proper order. Note that since we changed the time scale, and because WaitForSeconds is time scale dependent, we need to adjust for this in the ChangeColorRandom coroutine: