private void OnTriggerEnter2D(Collider2D collision) { // If we touch a collectable if (collision.CompareTag("Collectable")) { // Get the Collectable script component on the object Collectable collectable = collision.GetComponent <Collectable>(); // Fire the event and send the script object through OnPickupCollectable.Invoke(collectable); } // If we touch a saw, the player dies if (collision.gameObject.CompareTag("Saw")) { // Kill the player, give a reason Kill("You were sliced in half by a saw"); } // If we touch the water if (collision.CompareTag("Water")) { // Kill the player, give a reason Kill("You fell in the water and drowned"); } }
[SerializeField] private PickupEvent Pickup; // Event to trigger object being picked up private void FixedUpdate() { var pickups = GameObject.FindGameObjectsWithTag(WeaponTag); foreach (var pickup in pickups) { if (Vector2.Distance(this.transform.position, pickup.transform.position) <= PickupProximity) { // Was gonna use a tag approach, but since I need something to specify the weapon attributes, // I'm relying on the object to have a WeaponAttributes component to signify it is a weapon var wa = pickup.GetComponent <WeaponAttributes>(); if (wa != null) { Pickup.Invoke(wa.WeaponName); Destroy(pickup); } else { throw new UnityException("Tagged Weapon does not have an attached WeaponAttributes component!"); } } } }
public void PickUp(Pickup pickup) { // do stuff pickup.gameObject.SetActive(false); if (health != null) { health.ModifyStat(pickup.HealthDelta); } OnPickedUp.Invoke(pickup); }
[SerializeField] private PickupEvent Pickup; // Event to trigger object being picked up private void FixedUpdate() { var pickups = GameObject.FindGameObjectsWithTag(SkinTag); foreach (var pickup in pickups) { if (Vector2.Distance(this.transform.position, pickup.transform.position) <= PickupProximity) { Pickup.Invoke(); Destroy(pickup); } } }
bool PickupItem(Item item, Hands hand) { if (item == null) { return(false); } if ((item.transform.position - transform.position).magnitude > Range) { return(false); } switch (hand) { case Hands.LEFT: if (Hand1 != null) { return(false); } Hand1 = item; break; case Hands.RIGHT: if (Hand2 != null) { return(false); } Hand2 = item; break; } item.gameObject.SetActive(false); item.transform.parent = transform; item.transform.localPosition = new Vector3(0, 0, item.transform.localPosition.z); if (Hand1 != null && Hand2 != null) { for (int i = 0; i < ItemCombinations.Length; ++i) { ItemCombination combination = ItemCombinations[i]; if (combination.InputA == null || combination.InputB == null || combination.Output == null) { continue; } if ((combination.InputA.name == Hand1.name && combination.InputB.name == Hand2.name) || (combination.InputA.name == Hand2.name && combination.InputB.name == Hand1.name)) { activeCombination = i; break; } } } PickupEvent.Invoke(hand); return(true); }
public void PickObject() { if (CurrentHoverObject) { Item itemToPick = CurrentHoverObject.GetComponent <Item>(); if (itemToPick != null) { PickUpAction.Invoke(itemToPick); } else { Debug.Log("Item To Pick should have Item Script"); } } }
public override void OnInteract() { //If the item is pickupable, add it to inventory if (playerInventory.AddToInventory(item)) { if (audioSource) { audioSource.clip = pickupSound; audioSource.Play(); } PickupEvent?.Invoke(); Destroy(gameObject); } else { Debug.Log("Unable to add to inventory!"); } }
public override void OnInteract(GameObject Interactor) { base.OnInteract(Interactor); GameObject playerRef = Interactor; playerInventory = playerRef.GetComponent <InventoryManager>(); playerInteract = playerRef.GetComponent <InteractManager>(); audioSource = playerRef.GetComponent <AudioSource>(); //If the item is pickupable, add it to inventory if (playerInventory.AddToInventory(item)) { if (audioSource) { audioSource.clip = pickupSound; audioSource.Play(); } PickupEvent?.Invoke(Interactor); Destroy(gameObject); } }
public static void PickupBroadcast(Character character, Toteable toteable) { PickupEvent?.Invoke(character, toteable); }
internal void InvokePickup(SOPickupEventArgs ev) => PickupEvent?.Invoke(ev);
public void PickUp(BallBehaviour ball) { onPickUp.Invoke(ball); Destroy(gameObject); }
public void FirePickupEvent() { OnNewPickup.Invoke(CurrentPickup); }