IEnumerator _PurchaseCoffee(Transform _npc) { //Transform npc = purchaseQueue.Peek(); TestNPCQueue npcController = _npc.GetComponent <TestNPCQueue>(); //Debug.Log(npc.name + " buying coffee..."); yield return(new WaitForSeconds(npcController.TimeToOrder)); //Debug.Log(npc.name + " bought coffee."); purchaseQueue.Dequeue(); pickupQueue.Enqueue(_npc); Debug.Log(_npc.name + " added to pickupQueue"); _npc.parent = PickupPoint; npcController.PlaceInLine = pickupQueue.Count - 1; npcController.ChangeLine(TestNPCQueue.Line.pickup); npcController.MoveToLine(PickupPoint, TestNPCQueue.Line.pickup); int i = 0; foreach (Transform _npcs in purchaseQueue.ToArray()) { TestNPCQueue _npcsController = _npcs.GetComponent <TestNPCQueue>(); //Debug.Log("Moving " + _npc.name + " up one spot"); _npcsController.PlaceInLine = i; _npcsController.MoveUp(); i++; } yield return(null); }
IEnumerator NewCustomerGenerator() { int i = 0; yield return(new WaitForSeconds(1f)); while (i < TotalCustomers) { if (purchaseQueue.Count < MaxCustomers && pickupQueue.Count < MaxCustomers) { Transform newNPC = (Transform)Instantiate(NPC, SpawnPoint.position, SpawnPoint.rotation); newNPC.name = "NPC " + i.ToString(); TestNPCQueue NPCController = newNPC.GetComponent <TestNPCQueue>(); newNPC.parent = PurchasePoint; NPCController.PlaceInLine = purchaseQueue.Count; if (i == TotalCustomers - 1) { NPCController.PlaceInLine = purchaseQueue.Count + 3; } NPCController.ChangeLine(TestNPCQueue.Line.purchase); purchaseQueue.Enqueue(newNPC); //NPCController.MoveToLine(PurchasePoint); newCustomerTime = Random.Range(2, 6); i++; } yield return(new WaitForSeconds(newCustomerTime)); } }