Hello all Unity3D people i im making a health script and i want the Bloodtimer to go up 1 every 20 secounds this is my script
sing UnityEngine;
using System.Collections;
public class PL_Health : MonoBehaviour {
public int Health = 100;
public int MaxHealth = 100;
public int HealthBarSize = 100;
public int BloodTimer = 2;
public int BloodTimerMax = 100;
//Health pos
public int Pos1 = 10;
public int Pos2 = 10;
//Blood timer pos
public int Pos3 = 10;
public int Pos4 = 10;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if(Health > 100)
Health = 100;
if(Health == 0)
Application.LoadLevel("stage1");
if(BloodTimer == 100)
Application.LoadLevel("stage1");
}
void OnGUI()
{
GUI.color = Color.red;
GUI.Box(new Rect(Pos1,Pos2,HealthBarSize,30), Health + " / " + MaxHealth);
GUI.color = Color.blue;
GUI.Box(new Rect(Pos3,Pos4,HealthBarSize,30), BloodTimer + " / " + BloodTimerMax);
}
}
Yeah, so the best way will just be to modify the code I gave you to read;
bloodTimer += 1*Time.deltaTime;
//somewhere in the GUI
GUI.Box(new Rect(Pos3,Pos4,HealthBarSize,30), Mathf.RoundToInt(BloodTimer) + " / " + BloodTimerMax);
I may have put it in the wrong place, but basically, what I’ve done is rounded it for the GUI, but not modified the value, so on the back end of code it might read 10.4252652 or whatever, but on the GUI it reads 10. And doing this also won’t modify the value, just how it’s being displayed.