IEnumerator ManageAgents() { WaitForSeconds wait = new WaitForSeconds(0.5f); while (true) { yield return(wait); int i = 0; foreach (var agent in agentList) { if ((agent.transform.position - agent.destination).magnitude < 0.1f) { animators[i].SetBool("isWalking", false); float randomFloat = Random.Range(0f, 7f); NewDestination newDestination = new NewDestination(); newDestination.waitingTime = randomFloat; newDestination.agent = agent; newDestination.idAnim = i; hasBeenDeleted = false; newDestinationsCo.Add(StartCoroutine(nameof(SetNewDestination), newDestination)); } i++; } } }
public bool destSet; // True if a destination is set, false if it's not // Use this for initialization void Start() { currentOrders = Orders.IDLE; hasOrders = false; // Subscribe to the delegate OnDestChange += ChangeDest; }
IEnumerator SetNewDestination(NewDestination newDestination) { yield return(new WaitForSeconds(newDestination.waitingTime)); if (!hasBeenDeleted) { NavMeshPath navMeshPath = new NavMeshPath(); var targetPos = GetRandomPositionOnNavMesh(); newDestination.agent.CalculatePath(targetPos, navMeshPath); newDestination.agent.SetPath(navMeshPath); animators[newDestination.idAnim].SetBool("isWalking", true); } }