예제 #1
0
 public void BeginEnemyDeath(GameObject rewardPlayerInput)
 {
     attackingComponent.ToggleAttackCollider(false);
     rewardPlayer = rewardPlayerInput;
     animationComponent.SetAnimBool("Walking", false);
     animationComponent.SetAnimBool("Attacking", false);
     pathfindingComponent.rigidBody.constraints = RigidbodyConstraints2D.FreezeAll;
     animationComponent.SetAnimBool("Dying", true);
 }
예제 #2
0
    void Update()
    {
        switch (currentAIState)
        {
        case AIState.Idle:

            pathfindingComponent.ClearPath();
            attackComponent.RunAttackCooldownTimer();
            animationComponent.SetAnimBool("Walking", false);

            if (idleDelayTimer < idleDelayLength)
            {
                idleDelayTimer += Time.deltaTime;
            }
            else if (idleDelayTimer >= idleDelayLength)
            {
                currentAIState = AIState.FindingTarget;
            }
            break;

        case AIState.FindingTarget:

            idleDelayTimer  = 0f;
            attackPrepTimer = 0f;
            InitialiseTargets();
            FindNearestTarget();
            attackComponent.ToggleAttackCollider(true);
            animationComponent.SetAnimBool("Walking", false);
            attackComponent.RunAttackCooldownTimer();
            currentAIState = AIState.PursuingTarget;
            break;

        case AIState.PursuingTarget:

            SetFacingDirection();
            pathfindingComponent.PursureTarget();
            animationComponent.SetAnimBool("Walking", true);
            attackComponent.RunAttackCooldownTimer();
            if (attackComponent.inAttackRange == true)
            {
                currentAIState = AIState.AttackPrep;
            }
            break;

        case AIState.AttackPrep:
            animationComponent.SetAnimBool("Walking", false);
            if (attackPrepTimer < attackPrepLength)
            {
                attackPrepTimer += Time.deltaTime;
            }
            else
            {
                currentAIState = AIState.AttackSequence;
            }
            break;


        case AIState.AttackSequence:

            attackComponent.isAttacking = true;
            attackComponent.RunAttackCooldownTimer();

            //This would be the case that the target player has moved out of this objects attack range, after stepping into it.
            if (attackComponent.inAttackRange == false)
            {
                currentAIState = AIState.FindingTarget;
            }

            //This would be the case that the target player is within attack range & this objects attack isn't on cooldown.
            if (attackComponent.inAttackRange == true && attackComponent.attackCoolingDown == false)
            {
                animationComponent.SetAnimBool("Attacking", true);
            }
            break;

        case AIState.ExecutingAttacks:

            if (attackComponent.isAttacking == true)
            {
                attackComponent.ExecuteAttacks();
                attackComponent.attackTargets.Clear();
                attackComponent.isAttacking         = false;
                attackComponent.attackCoolDownTimer = 0f;
                attackComponent.attackCoolingDown   = true;
            }

            if (attackComponent.inAttackRange == false)
            {
                currentAIState = AIState.FindingTarget;
            }
            else
            {
                currentAIState = AIState.AttackSequence;
            }
            break;

        default:
            break;
        }
    }