Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class LampLife : MonoBehaviour {
- public float minimumLife = 1;
- public float powerLife = 20;
- public float counterLife;
- public float speedOfTheGame = 1.5f;
- public RawImage image;
- private Light lamp;
- public Text powerLifeText;
- private void Start(){
- lamp = GetComponentInChildren<Light>();
- lamp.enabled = false;
- }
- private void Update(){
- counterLife = speedOfTheGame * Time.deltaTime;
- if((int)powerLife <= 20 && (int)powerLife >= 10){
- image.color = Color.green;
- }
- else if((int)powerLife >= 5 && (int)powerLife <= 10){
- image.color = Color.yellow;
- }
- else if((int)powerLife > 0 && (int)powerLife <= 5){
- image.color = Color.red;
- }
- else if(powerLife >= 0 && powerLife < 1){
- lamp.enabled = false;
- }
- if(powerLife >= minimumLife && lamp.enabled != false){
- powerLife -= counterLife;
- }
- powerLifeText.text = (int)powerLife + " % ";
- }
- public void GetPowerLife(int power){
- powerLife += power;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment