patriot_ua

health box [2]

Mar 3rd, 2016
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.28 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. [RequireComponent(typeof(AudioSource))]
  5. public class HealthBox : MonoBehaviour
  6. {
  7.     public float addHealthVal = 10;
  8.     public string userTag;
  9.     public KeyCode key;
  10.  
  11.     public int countUse = 3;
  12.  
  13.     public AudioSource source;
  14.  
  15.     private bool isShowTooltip = false;
  16.  
  17.     public void OnTriggerEnter(Collider coll)
  18.     {
  19.         if (coll.gameObject.tag.Equals(userTag))
  20.             isShowTooltip = true;
  21.     }
  22.  
  23.     public void OnTriggerExit(Collider coll)
  24.     {
  25.         if (coll.gameObject.tag.Equals(userTag))
  26.             isShowTooltip = false;
  27.     }
  28.  
  29.     public void OnTriggerStay(Collider coll)
  30.     {
  31.         if (Input.GetKeyDown(key) && coll.gameObject.tag.Equals(userTag))
  32.         {
  33.             HealthUser health = coll.gameObject.GetComponent<HealthUser>();
  34.  
  35.             if (health.getHealth() >= 100)
  36.                 return;
  37.  
  38.             health.addHealth(addHealthVal);
  39.  
  40.             health = null;
  41.             countUse--;
  42.  
  43.             source.Play();
  44.  
  45.             if (countUse < 1)
  46.                 Destroy(gameObject);
  47.         }
  48.     }
  49.  
  50.     public void OnGUI()
  51.     {
  52.         if (isShowTooltip)
  53.         {
  54.             GUI.Box(new Rect(100, 50, 100, 30), "THIS IS TOOLTIP HEALTH-BOX");
  55.         }
  56.     }
  57. }
Add Comment
Please, Sign In to add comment