void InitiatePizzaResupply(DeliveryTruck receiver) { //make sure the truck is going slow enough to receive pizzas if (receiver.GetComponent <Rigidbody>().velocity.magnitude < speedTolerance) { //it is! wait a sec, then drop the 'zas supplying = true; pizzasToGiveThisTrip = truck.getMaxPizzas() - truck.HowManyPizzas(); spawnTimer = delayBeforeResupply; } }
// Update is called once per frame void OnTriggerStay(Collider other) { //if there's a truck in the bay, start resupplying pizzas! if (other.gameObject.CompareTag("DeliveryTruck")) { truck = other.GetComponent <DeliveryTruck>(); //if the truck's already got enough pizzas, ignore it if (truck.HowManyPizzas() >= truck.getMaxPizzas()) { return; } if (supplying == false) { InitiatePizzaResupply(truck); } } }