Created
July 11, 2021 22:06
-
-
Save robotron2084/fce8587d9b54b0a5f6ffdcd48b53c00e 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 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(); | |
} | |
} | |
} | |
} | |
} |
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 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