From d2ab30e7a69bfe7efda63ae75812207377917bd3 Mon Sep 17 00:00:00 2001 From: miepzerino <o.skotnik@gmail.com> Date: Sun, 30 Mar 2025 18:50:27 +0000 Subject: [PATCH] Merge branch 'Flexalon-UI-Layouts' into develop --- Assets/Scripts/Inventory/Pickup.cs | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 45 insertions(+), 0 deletions(-) diff --git a/Assets/Scripts/Inventory/Pickup.cs b/Assets/Scripts/Inventory/Pickup.cs new file mode 100644 index 0000000..c0d0171 --- /dev/null +++ b/Assets/Scripts/Inventory/Pickup.cs @@ -0,0 +1,45 @@ +using Assets.Scripts.Enums; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class Pickup : MonoBehaviour +{ + public Item item; + + public Vector3 spinRotatationSpeed = new Vector3(0, 180, 0); + + public SoundName soundName; + + + private void OnCollisionEnter2D(Collision2D collision) + { + Collider2D collider = collision.collider; + // get <Inventory> object if collision object has it + Inventory inventory = collider.GetComponent<Inventory>(); + Debug.Log("Pickup collected by: " + collision.gameObject); + Debug.Log("Inventory: " + inventory); + // OnTrigger with <Inventory> + if (inventory) + { + // Pickup health if not at max HP + if (inventory.AddItem(item)) + { + SoundManager.instance.PlaySoundAtPoint(gameObject, soundName); + Destroy(gameObject); + } + } + } + + //private void OnTriggerStay2D(Collider2D collision) + //{ + // // pickup while inside collision + // OnCollisionEnter2D(collision); + //} + + private void Update() + { + // rotate pickup object + transform.eulerAngles += spinRotatationSpeed * Time.deltaTime; + } +} -- Gitblit v1.9.3