Example #1
0
        void Update()
        {
            // print(target);
            weaponSystem       = GetComponent <WeaponSystem>();
            currentWeaponRange = weaponSystem.UpdateCurrentWeapon.GetMaxAttackRange();

            if (target != null && target.gameObject.tag != ("Animal"))
            {
                distanceToEnemy      = Vector3.Distance(target.transform.position, transform.position);
                isInWeaponCircle     = distanceToEnemy <= currentWeaponRange;
                isInChaseCircle      = (distanceToEnemy > currentWeaponRange && distanceToEnemy <= chaseRadius);
                isOutsideChaseCircle = distanceToEnemy > chaseRadius;
            }
            else if (target == null)
            {
                isOutsideChaseCircle = true;
                isInWeaponCircle     = false;
                isInChaseCircle      = false;
            }

            if (isOutsideChaseCircle)
            {
                weaponSystem.StopAttacking();
                StartCoroutine(Patrol());
            }

            if (isInChaseCircle)
            {
                StopAllCoroutines();
                float animatorForwardCap = 1f;
                character.SetAnimatorForwardCap(animatorForwardCap);
                weaponSystem.StopAttacking();
                StartCoroutine(ChaseTarget());
            }
            else if (!isInWeaponCircle && !isInChaseCircle)
            {
                float animatorForwardCap = 0.5f;
                character.SetAnimatorForwardCap(animatorForwardCap);
            }

            if (isInWeaponCircle)
            {
                if (weaponSystem)
                {
                    weaponSystem.AttackTarget(target.gameObject);
                }
                StartCoroutine(PatrolWaitWhenAttacking());
            }
        }
Example #2
0
 void OnMouseOverPotentiallyWalkable(Vector3 destination)
 {
     if (Input.GetMouseButtonDown(0))
     {
         weaponSystem.StopAttacking();
         character.SetDestination(destination);
     }
 }