Created
August 13, 2018 07:00
-
-
Save Makizemi/2798405e65a383b8675d37af05ff28bb to your computer and use it in GitHub Desktop.
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
public abstract class BaseState | |
{ | |
public virtual BaseState Update() | |
{ | |
return null; | |
} | |
} | |
public class IdleState : BaseState | |
{ | |
public override BaseState Update() | |
{ | |
if(移動の入力があれば) | |
{ | |
return new MoveState(); | |
} | |
return null; | |
} | |
} | |
public class MoveState : BaseState | |
{ | |
public override BaseState Update() | |
{ | |
if(移動していなければ) | |
{ | |
return new IdleState(); | |
} | |
Move(); | |
return null; | |
} | |
void Move() | |
{ | |
//移動の処理 | |
} | |
} |
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
using UnityEngine; | |
public class Main:MonoBehaviour | |
{ | |
BaseState state; | |
void Start() | |
{ | |
state = new IdleState(); | |
} | |
void Update() | |
{ | |
BaseState currentState = state.Update(); | |
if (currentState != null) | |
{ | |
state = currentState; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment