Question by
cepoimario280135 · May 22, 2020 at 01:30 PM ·
gameobjectlistdistancefloatcheck
Get the lowest value from a Gameobject List
How can i obtain a gameobject from the list based on how far is the agent from the list ?
In here every ai agent has an AISight component that contain a distance float value to calculate between itself and the current target , Based on that what would be the best approach in order to assign the closest ai agent to a target as a currentLeader
public class AiGroupManager : MonoBehaviour { public List<GameObject> aiGroup; public List<GameObject> aiWithTarget; public GameObject currentLeader; void GetLeader() { if (currentLeader == null) { for (int i = 0; i < aiGroup.Count; ++i) { // if (aiGroup[i].GetComponent<AISight>().ClosestTarget != null) { if (!aiWithTarget.Contains(aiGroup[i].gameObject)) { var ss = aiGroup[i].gameObject; aiWithTarget.Add(ss); } }
Comment