Пример #1
0
        protected override void SetUpStates()
        {
            var idleState           = new IdleState(this);
            var largeAttackState    = new AttackState(enemyWeapon, Animator, Mover, Player);
            var prepareShortAttack  = new PlayAnimationState(Animator, Player, Mover, "prepareShortAttack", 0.5f);
            var shortRangeState     = new AttackState(shortRangeWeapon, transform, Mover, Player);
            var idleShortRangeState = new IdleState(this);
            var dieAnimation        = new PlayAnimationState(Animator, Player, Mover, "die", 0.67f);
            var destroySelf         = new DestroySelfState(gameObject);

            StateMachine.AddTransition(idleState, largeAttackState, PlayerInsideRange);
            StateMachine.AddTransition(largeAttackState, idleState, () => !PlayerInsideRange());
            StateMachine.AddTransition(largeAttackState, prepareShortAttack, HealthBelowThreshold);
            StateMachine.AddTransition(prepareShortAttack, idleShortRangeState, FinishPlayingAnimation(prepareShortAttack));
            StateMachine.AddTransition(idleShortRangeState, shortRangeState, PlayerInsideRange);
            StateMachine.AddTransition(shortRangeState, idleShortRangeState, () => !PlayerInsideRange());

            StateMachine.AddAnyTransition(dieAnimation, EnemyDie);
            StateMachine.AddTransition(dieAnimation, destroySelf, FinishPlayingAnimation(dieAnimation));

            StateMachine.SetState(idleState);

            _initialHealth = Stats.Health;
            bool HealthBelowThreshold() => Stats.Health <= _initialHealth *laserHealthPercentage;
        }
Пример #2
0
        protected override void SetUpStates()
        {
            var idleState           = new IdleState(leftPosition, rightPosition, this, Mover);
            var startAttackingState =
                new PlayAnimationState(Animator, Player, Mover, "startAttacking", prepareToAttackAnimationLength);
            var attackState        = new AttackState(enemyWeapon, Animator, Mover, Player);
            var stopAttackingState =
                new PlayAnimationState(Animator, Player, Mover, "stopAttacking", prepareToAttackAnimationLength);
            var dieState    = new PlayAnimationState(Animator, Player, Mover, "die", dieAnimationLength);
            var destroySelf = new DestroySelfState(gameObject);

            StateMachine.AddTransition(idleState, startAttackingState, PlayerInsideRange);
            StateMachine.AddTransition(startAttackingState, attackState, FinishPlayingAnimation(startAttackingState));
            StateMachine.AddTransition(attackState, stopAttackingState, PlayerOutsideRange);
            StateMachine.AddTransition(stopAttackingState, idleState, FinishPlayingAnimation(stopAttackingState));
            StateMachine.AddTransition(dieState, destroySelf, FinishPlayingAnimation(dieState));

            StateMachine.AddAnyTransition(dieState, EnemyDie);

            StateMachine.SetState(idleState);

            bool PlayerOutsideRange() => !PlayerInsideRange();
        }