Пример #1
0
        // Get targets sorted by distance
        public IEnumerable <Character> GetTargets()
        {
            var search = new CharacterSearch();

            search.character   = character;
            search.maxDistance = character.vision;
            return(Characters.Instance.GetTargets(search));
        }
Пример #2
0
        // Search for characters, returns in order of distance
        public IEnumerable <Character> GetTargets(CharacterSearch search)
        {
            var maxDisSq = search.maxDistance * search.maxDistance;

            return(characters.Values.Where(u => {
                if (u == search.character)
                {
                    return false;
                }

                var disSq = (u.gameObject.transform.position - search.character.transform.position).sqrMagnitude;
                if (disSq > maxDisSq)
                {
                    return false;
                }

                return u.isMonster != search.character.isMonster;
            }).OrderBy(u => (u.gameObject.transform.position - search.character.transform.position).sqrMagnitude));
        }