Example #1
0
        IEnumerator waitFindTarget(float interval)
        {
            yield return(new WaitForSeconds(interval));

            targetTeamPlayer = CharacterMap.Instance.GetTarget(teamPlayer, searchRange);
            yield return(waitFindTarget(interval));
        }
Example #2
0
        public TeamPlayer GetTarget(TeamPlayer teamPlayer, float searchRange)
        {
            int teamIndex       = teamPlayer.teamIndex;
            int targetTeamIndex = Random.Range(0, teams.Count);

            while (targetTeamIndex == teamIndex)
            {
                targetTeamIndex = Random.Range(0, teams.Count);
            }

            return(GetTargetByTeamIndex(teamPlayer, searchRange, targetTeamIndex));
        }
Example #3
0
        public TeamPlayer GetTargetByTeamIndex(TeamPlayer teamPlayer, float searchRange, int targetTeamIndex)
        {
            TeamPlayer _target  = null;
            float      distance = searchRange;

            foreach (var target in teams[targetTeamIndex].players)
            {
                float _distance = (target.transform.position - teamPlayer.transform.position).magnitude;
                if (_distance < distance)
                {
                    _target  = target;
                    distance = _distance;
                }
            }
            return(_target);
        }