示例#1
0
 void OnMouseOverEnemy(EnemyAI enemy)
 {
     if (Input.GetMouseButton(0) && IsTargetInRange(enemy.gameObject))
     {
         //    print("In Range");
         weaponSystem.AttackTarget(enemy.gameObject);
     }
     else if (Input.GetMouseButton(0) && !IsTargetInRange(enemy.gameObject))
     {
         //   print("move and attack");
         StartCoroutine(MoveAndAttack(enemy));
     }
 }
示例#2
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());
            }
        }