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 object if collision object has it Inventory inventory = collider.GetComponent(); Debug.Log("Pickup collected by: " + collision.gameObject); Debug.Log("Inventory: " + inventory); // OnTrigger with 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; } }