Skip to content

Instantly share code, notes, and snippets.

@robotron2084
Created July 11, 2021 22:06
Show Gist options
  • Save robotron2084/fce8587d9b54b0a5f6ffdcd48b53c00e to your computer and use it in GitHub Desktop.
Save robotron2084/fce8587d9b54b0a5f6ffdcd48b53c00e to your computer and use it in GitHub Desktop.
public class EnemyUnit
{
public bool Enabled; // Is the object active within the environment?
public bool IsAlive; // Has the object been killed yet?
public bool CanBeHit; // Can the enemy be hit or is it currently invulnerable or dead?
public void OnHit()
{
if(Enabled)
{
if(IsAlive)
{
if(CanBeHit)
{
DoDamage();
}
}else
{
if(CanBeHit)
{
PlayCorpsehit();
}
}
}
}
}
public class EnemyUnitFSM
{
public enum States
{
Alive,
Hit,
Dead,
CorpseHit
}
public void OnHit()
{
if(stateMachine.CurrentState == States.Alive)
{
stateMachine.SetState(States.Hit);
}else if(stateMachine.CurrentState == States.Dead){
stateMachine.SetState(States.CorpseHit);
}
}
public Task Hit_Update(CancellationToken ct)
{
doDamage();
if(stateMachine.CurrentState == States.Dead)
{
return;
}
await playHitAnimation();
stateMachine.SetState(States.Alive);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment