Advertisement
kadyr

Untitled

Feb 17th, 2022
1,017
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.88 KB | None | 0 0
  1. public class Ajdaha:Enemy
  2. {
  3.  
  4. }
  5.  
  6. public enum EnemyState
  7. {
  8.     idle,
  9.     run,
  10.     attack
  11. }
  12. public abstract class StatableBehaviour:Monobehaviour
  13. {
  14.     public EnemyState currentState;
  15.     public virtual void StateBehaviour(EnemyState state) => if(state != currentState) return;
  16. }
  17. public class Move: StatableBehaviour
  18. {
  19.     void Start()
  20.     {
  21.         currentState = EnemyState.run;
  22.     }
  23.     public override void StateBehaviour(EnemyState state){
  24.         base.StateBehaviour();
  25.         transform.position += Vector3.one;
  26.     }
  27. }
  28. public abstract class Enemy:Monobehaviour
  29. {
  30.     private EnemyState state;
  31.     public EnemyState State{
  32.         get => return state;
  33.         set {
  34.             state = value;
  35.             onStateChanged?.Invoke(state);
  36.         }
  37.     }
  38.     public event Action<EventState state> onStateChanged;
  39.     public StatableBehaviour[] behaviours;
  40.     void Start()
  41.     {
  42.         foreach(var t in behaviours)
  43.         {
  44.             onStateChanged += t.StateBehaviour;
  45.         }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement