Game Development Reference
In-Depth Information
Simple singular choice
The simplest way to implement a state system is using the C# switch statement; the be-
nefit here is that there can only be a single result:
if (Input.GetButtonDown("Up"))
{
switch (currentTvState)
{
case TvState.Off:
//Nothing, tv is off
break;
case TvState.On:
//Channel Up
break;
case TvState.Menu:
//Menu selection up
break;
}
}
So as you can see in the previous example, we have simply implemented the pattern for
the Up button on the remote, and depending on what the television is doing currently, it
will act appropriately.
This is good for menus, but is limiting in situations where based on the state, we might
want to do multiple things.
Search WWH ::




Custom Search