Created
July 27, 2017 14:56
-
-
Save joobei/324d6998f01812ea589fb1047e34d4a5 to your computer and use it in GitHub Desktop.
Monobehaviour problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class State: Monobehaviour { | |
//reference to the state we will need to jump to | |
public State nextState; | |
protected virtual void Update() | |
{ | |
if (mouseClicked) | |
{ | |
doSomething(); | |
advance(); | |
} | |
} | |
protected abstract void doSomething(); | |
public virtual void advanceState() | |
{ | |
//disable this state (i.e. update will stop being called) | |
enabled = false; | |
//enable the next one | |
nextState.Activate(); | |
} | |
public virtual void Activate() | |
{ | |
this.enabled = true; | |
} | |
} | |
//First child state | |
class FirstState: State { | |
protected override void doSomething() | |
{ | |
Debug.Log("FirstState"); | |
} | |
} | |
//second child state | |
class SecondState: State { | |
protected override void doSomething() | |
{ | |
Debug.Log("SecondState"); | |
} | |
} | |
//output in console when advancing from firstState to secondState: | |
FirstState | |
SecondState |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment