Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- [RequireComponent(typeof(AudioSource))]
- public class HealthBox : MonoBehaviour
- {
- public float addHealthVal = 10;
- public string userTag;
- public KeyCode key;
- public int countUse = 3;
- public AudioSource source;
- private bool isShowTooltip = false;
- public void OnTriggerEnter(Collider coll)
- {
- if (coll.gameObject.tag.Equals(userTag))
- isShowTooltip = true;
- }
- public void OnTriggerExit(Collider coll)
- {
- if (coll.gameObject.tag.Equals(userTag))
- isShowTooltip = false;
- }
- public void OnTriggerStay(Collider coll)
- {
- if (Input.GetKeyDown(key) && coll.gameObject.tag.Equals(userTag))
- {
- HealthUser health = coll.gameObject.GetComponent<HealthUser>();
- if (health.getHealth() >= 100)
- return;
- health.addHealth(addHealthVal);
- health = null;
- countUse--;
- source.Play();
- if (countUse < 1)
- Destroy(gameObject);
- }
- }
- public void OnGUI()
- {
- if (isShowTooltip)
- {
- GUI.Box(new Rect(100, 50, 100, 30), "THIS IS TOOLTIP HEALTH-BOX");
- }
- }
- }
Add Comment
Please, Sign In to add comment