miepzerino
2023-12-25 f69bd91a28797df42f32c342a0d0305d08278a93
Assets/Scripts/Pickup.cs
@@ -1,3 +1,4 @@
using Assets.Scripts.Enums;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
@@ -8,16 +9,21 @@
    public Vector3 spinRotatationSpeed = new Vector3(0, 180, 0);
    public SoundName soundName;
    private void OnTriggerEnter2D(Collider2D collision)
    {
        // get <Damageable> object if collision object has it
        Damageable damageable = collision.GetComponent<Damageable>();
        // OnTrigger with <Damageable>
        if (damageable)
        {
            // Pickup health if not at max HP
            if (damageable.Heal(healthRestore))
            {
                SoundManager.instance.PlaySoundAtPoint(gameObject, soundName);
                Destroy(gameObject);
            }
        }
@@ -25,11 +31,13 @@
    private void OnTriggerStay2D(Collider2D collision)
    {
        // pickup while inside collision
        OnTriggerEnter2D(collision);
    }
    private void Update()
    {
        // rotate pickup object
        transform.eulerAngles += spinRotatationSpeed * Time.deltaTime;
    }
}