public IEnumerator TestPillCooldown() { GameObject pillGo = new GameObject(); pillGo.AddComponent <Pill>(); IPickupable pickup = pillGo.GetComponent <IPickupable>(); Assert.IsNotNull(pickup); TestGrabber grabber = new TestGrabber(); Assert.IsTrue(pickup.CanPickup(grabber)); pickup.OnPickup(grabber); Assert.IsFalse(pickup.CanPickup(grabber)); pickup.OnDrop(grabber); // Should not be pickupable for 1 second of cooldown. Assert.IsFalse(pickup.CanPickup(grabber)); // Wait for cooldown - then should be pickupable. yield return(new WaitForSeconds(1.1f)); Assert.IsTrue(pickup.CanPickup(grabber)); }
void OnAction() { IPickupable target = targetRef.Get(); if (carrying) { target.OnDrop(this); carrying = false; } else { if (target.CanPickup(this)) { target.OnPickup(this); carrying = true; } else { Debug.Log("Woops - can't pick up " + target.GetName() + " yet"); } } }