Skip to content

Instantly share code, notes, and snippets.

@Makizemi
Created August 13, 2018 07:00
Show Gist options
  • Save Makizemi/2798405e65a383b8675d37af05ff28bb to your computer and use it in GitHub Desktop.
Save Makizemi/2798405e65a383b8675d37af05ff28bb to your computer and use it in GitHub Desktop.
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()
{
//移動の処理
}
}
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