Пример #1
0
        public GameObject GetNearestPlayer()
        {
            GameObject[] players = GameObject.FindGameObjectsWithTag("Player");
            GameObject   closest = AIHelpers.FindClosest(players, transform);

            return(closest);
        }
Пример #2
0
 void UpdateGroundedState()
 {
     if (animator != null)
     {
         if (ignoreGroundCheck == true)
         {
             return;
         }
         if (AIHelpers.RaycastHitting(transform, groundRaycast, Vector3.down, 0.4f))
         {
             grounded = true;
             animator.SetBool(animatorNames.grounded, true);
         }
         else
         {
             grounded = false;
             animator.SetBool(animatorNames.grounded, false);
         }
     }
     else if (animationcomp != null)
     {
         if (AIHelpers.RaycastHitting(transform, groundRaycast, Vector3.down, 0.4f))
         {
             grounded = true;
         }
         else
         {
             grounded = false;
             animationcomp.CrossFade(animList.fall);
         }
     }
 }
Пример #3
0
        public void Attack(GameObject overrideTarget = null)
        {
            if (number_of_allowed_attacks < 1)
            {
                return;
            }
            number_of_allowed_attacks -= 1;
            if (isDebugging == true)
            {
                Debug.Log(name + " attacked");
            }
            AIMemory   memory = GetComponent <AIMemory>();
            GameObject target = null;

            if (overrideTarget == null)
            {
                target = memory.GetTarget();
            }
            else
            {
                target = overrideTarget;
            }
            if (target == null)
            {
                return;
            }
            GameObject returnTarget = AIHelpers.InaccurateRaycast(
                target.transform,
                memory.GetEyes().transform,
                memory.GetIgnoreLayers(),
                memory.GetOffsetRange(),
                memory.GetInaccuracy(),
                memory.GetFireRange(),
                isDebugging
                );

            PlayMuzzleFlash();
            PlayWeaponSound();
            if (returnTarget != null)
            {
                if (isDebugging == true)
                {
                    Debug.Log(name + " sending damage to " + returnTarget.transform.root.name);
                }
                if (returnTarget.transform.root.GetComponent <Health>())
                {
                    returnTarget.transform.root.GetComponent <Health>().ApplyDamage(memory.GetRangeDamageAmount(), gameObject);
                }
            }
        }
Пример #4
0
        public void BroadCastTargetPosition()
        {
            AIMemory memory   = GetComponent <AIMemory>();
            Vector3  position = memory.GetLastTargetPosition();
            float    distance = memory.GetShoutDistance();

            string[]     friendTags = memory.GetFriendTags();
            GameObject[] friends    = AIHelpers.GetAllGameObjectsInRange(friendTags, distance);
            foreach (GameObject friend in friends)
            {
                friend.GetComponent <AIMemory>().SetLastTargetPosition(position);
                friend.GetComponent <AIMemory>().SetIncreasedLevel();
            }
        }