Ejemplo n.º 1
0
        void SE_UpdateEnemyAI()
        {
            distanceToPlayer = Vector3.Distance(player.transform.position, transform.position);
            WeaponSystem weaponSystem = GetComponent <WeaponSystem>();

            currentWeaponRange = weaponSystem.GetCurrentWeapon().GetMaxAttackRange();

            bool inWeaponCircle = distanceToPlayer <= currentWeaponRange;
            bool inChaseRing    = distanceToPlayer > currentWeaponRange
                                  &&
                                  distanceToPlayer <= chaseRadius;
            bool outsideChaseRing = distanceToPlayer > chaseRadius;

            if (outsideChaseRing)
            {
                StopAllCoroutines();
                weaponSystem.StopAttacking();
                StartCoroutine(Patrol());
            }
            if (inChaseRing)
            {
                StopAllCoroutines();
                weaponSystem.StopAttacking();
                StartCoroutine(ChasePlayer());
            }
            if (inWeaponCircle)
            {
                StopAllCoroutines();
                state = State.attacking;
                weaponSystem.AttackTarget(player.gameObject);
            }
        }
Ejemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        distanceToPlayer = Vector3.Distance(player.transform.position, transform.position);
        WeaponSystem weaponSystem = GetComponent <WeaponSystem>(); // No performance issue

        currentWeaponRange = weaponSystem.GetCurrentWeapon().GetMaxAttackRange();

        bool inWeaponRadius     = distanceToPlayer <= currentWeaponRange;
        bool inChaseRadius      = distanceToPlayer > currentWeaponRange && distanceToPlayer <= chaseRadius;
        bool outsideChaseRadius = distanceToPlayer > chaseRadius;

        if (inWeaponRadius)
        {
            print("inWeaponRadius");
            StopAllCoroutines();
            state = State.attacking;
            transform.LookAt(player.gameObject.transform);
            weaponSystem.AttackTarget(player.gameObject);
            character.GetNavMeshAgent().isStopped = true;
            character.GetNavMeshAgent().velocity  = Vector3.zero;
        }

        if (outsideChaseRadius)
        {
            print("outsideChaseRadius");
            StopAllCoroutines();
            StartCoroutine(Patrol());
        }

        if (inChaseRadius)
        {
            print("inChaseRadius");
            StopAllCoroutines();
            weaponSystem.StopAttacking();
            character.GetNavMeshAgent().isStopped = false;
            StartCoroutine(ChasePlayer());
        }
    }