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);
}
}
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter