public IEnumerator movePacket(GameObject packet, GameObject link, GameObject nodeToMoveTo) { link.GetComponent <LinkInUse>().setInUse(); float speed = packet.GetComponent <Packet>().getSpeed(); float moveX = (nodeToMoveTo.transform.position.x - packet.transform.position.x) / link.GetComponent <LinkLength>().getLength(); float moveY = (nodeToMoveTo.transform.position.y - packet.transform.position.y) / link.GetComponent <LinkLength>().getLength(); float nodePosXUpper = nodeToMoveTo.transform.position.x + 1.5f; float nodePosXLower = nodeToMoveTo.transform.position.x - 1.5f; float nodePosYUpper = nodeToMoveTo.transform.position.y + 1.5f; float nodePosYLower = nodeToMoveTo.transform.position.y - 1.5f; if (remPackets.getPackets() == 1 && packet.GetComponent <Packet>().target == nodeToMoveTo) { Time.timeScale = 2; } while (!( packet.transform.position.x > nodePosXLower && packet.transform.position.x < nodePosXUpper && packet.transform.position.y > nodePosYLower && packet.transform.position.y < nodePosYUpper )) { packet.transform.position = new Vector3(packet.transform.position.x + (speed * moveX), packet.transform.position.y + (speed * moveY), 0); yield return(new WaitForFixedUpdate()); } link.GetComponent <LinkInUse>().endUse(); packetArrives(nodeToMoveTo, packet); if (Time.timeScale > 1) { Time.timeScale = 1; } }
// Update is called once per frame void Update() { remainingPacketsText.text = "Packets Remaining: " + remainingPackets.getPackets(); }