コード例 #1
0
ファイル: EnemyAI.cs プロジェクト: emilizz1/RPG
        void Update()
        {
            WeaponSystem weaponSystem = GetComponent <WeaponSystem>();

            currentWeaponRange = weaponSystem.GetCurrentWeapon().GetMaxAttackRange();
            distanceToPlayer   = Vector3.Distance(player.transform.position, transform.position);

            if (isAlive)
            {
                bool inWeaponRange     = distanceToPlayer <= currentWeaponRange;
                bool inChaseRange      = distanceToPlayer > currentWeaponRange && distanceToPlayer <= chaseRadius;
                bool outsideChaseRange = distanceToPlayer > chaseRadius;

                if (inChaseRange)
                {
                    StopAllCoroutines();
                    weaponSystem.StopAttacking();
                    StartCoroutine(ChasePlayer());
                    character.ReturnAnimationFowardCap();
                }
                else if (inWeaponRange)
                {
                    StopAllCoroutines();
                    state = State.attacking;
                    weaponSystem.AttackTarget(player.gameObject);
                }
                else if (outsideChaseRange && state != State.patrolling)
                {
                    StopAllCoroutines();
                    weaponSystem.StopAttacking();
                    StartCoroutine(Patrol());
                }
            }
            else
            {
                StopAllCoroutines();
            }
        }