Nekrosincoding

Simple

Jun 24th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.07 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5.  
  6. public class LampLife : MonoBehaviour {
  7.  
  8.     public float minimumLife = 1;
  9.     public float powerLife = 20;
  10.     public float counterLife;
  11.     public float speedOfTheGame = 1.5f;
  12.     public RawImage image;
  13.     private Light lamp;
  14.     public Text powerLifeText;
  15.  
  16.     private void Start(){
  17.         lamp = GetComponentInChildren<Light>();
  18.         lamp.enabled = false;
  19.     }
  20.  
  21.     private void Update(){
  22.         counterLife = speedOfTheGame * Time.deltaTime;
  23.         if((int)powerLife <= 20 && (int)powerLife >= 10){
  24.             image.color = Color.green;
  25.         }
  26.         else if((int)powerLife >= 5 && (int)powerLife <= 10){
  27.             image.color = Color.yellow;
  28.         }
  29.         else if((int)powerLife > 0 && (int)powerLife <= 5){
  30.             image.color = Color.red;
  31.         }
  32.         else if(powerLife >= 0 && powerLife < 1){
  33.             lamp.enabled = false;
  34.         }
  35.  
  36.         if(powerLife >= minimumLife && lamp.enabled != false){
  37.             powerLife -= counterLife;
  38.         }
  39.         powerLifeText.text = (int)powerLife + " % ";
  40.     }
  41.    
  42.     public void GetPowerLife(int power){
  43.         powerLife += power;
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment