HealthPickup | FEP

PHOTO EMBED

Thu May 12 2022 17:29:56 GMT+0000 (Coordinated Universal Time)

Saved by @BiscuitTinx #c#

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class HealthPickup : MonoBehaviour
{
    // Audio
    public AudioSource Audio;
    public AudioClip HealthSound;

    public Transform meshes;

    bool isPickedUp = false;

    private void OnTriggerEnter(Collider c)
    {
        // checks for player and is pickable 
        if (c.tag == "Player" && !isPickedUp)
        {
            Health playerHealth = c.GetComponent<Health>();

            if (playerHealth.health >= playerHealth.maxHealth) return;

            Audio.PlayOneShot(HealthSound);
            playerHealth.health = playerHealth.maxHealth;
            isPickedUp = true;
            meshes.gameObject.SetActive(false);
        }
    }
}
content_copyCOPY