예제 #1
0
        void clearDeadFromNearbyEnemiesList()
        {
            List <PlayerControllerComponent> nearbyEnemiesToRemove = new List <PlayerControllerComponent>();

            for (int i = 0; i < nearbyEnemies.Count; i++)
            {
                PlayerControllerComponent pcc = nearbyEnemies[i];
                if (pcc.isDead())
                {
                    nearbyEnemiesToRemove.Add(pcc);
                }
            }
            nearbyEnemies.RemoveAll(item => nearbyEnemiesToRemove.Contains(item));
        }
예제 #2
0
        public virtual void onTargetButtonClicked()
        {
            clearDeadFromNearbyEnemiesList();
            // If no nearby players.
            if (nearbyEnemies.Count <= 0)
            {
                setTarget(null);
                return;
            }

            if (currentTarget)
            {
                PlayerControllerComponent targetPcc = currentTarget.GetComponent <PlayerControllerComponent>();
                int index = nearbyEnemies.IndexOf(targetPcc);

                // current target doest not exists in nearbyPlayers
                if (index > nearbyEnemies.Count - 1 || index < 0)
                {
                    // current target is not available \ out of range

                    // get closest enemy
                    setTarget(nearbyEnemies[0].GetComponent <Transform>());
                }
                else
                {
                    // target next enemy
                    index++;

                    // if next index is out of bounds, start again from index 0;
                    if (index > nearbyEnemies.Count - 1)
                    {
                        index = 0;
                    }

                    // if after target rotation we reached the same target, dont set new target.
                    // could happen if there is only one enemy in range, and we try to get new target. (we dont want the target sound to play again)
                    if (nearbyEnemies[index] != currentTarget)
                    {
                        setTarget(nearbyEnemies[index].GetComponent <Transform>());
                    }
                }
            }
            else
            {
                // dont have a target yet, target first available.
                setTarget(nearbyEnemies[0].GetComponent <Transform>());
            }
        }
예제 #3
0
 void OnTriggerEnter(Collider other)
 {
     if (other.tag == "Player")
     {
         //TODO: check if enemy
         PlayerControllerComponent otherPcc = other.transform.GetComponent <PlayerControllerComponent>();
         if (otherPcc.isDead())
         {
             return;
         }
         if (!nearbyEnemies.Contains(otherPcc))
         {
             // add enemy to nearby list.
             nearbyEnemies.Add(otherPcc);
         }
     }
 }