Help with a timer

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);
	}
	
}

Quickest way is to call Time.deltaTime, so we can say something like;

bloodTimer += (1 * Time.deltaTime);

Thanks that helped alot but it shows numbers like this 10.198749 how do i make it so it shows only 1, 2 ,3 ,4 ETC

On the GUI? I think the best way to do that would be to use Mathf.RoundToInt, that way it will always round to the nearest integer.

Can you give me an example im kinda new to C#

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.

Yay it works thank you so much man i have been searching how to do this for hours and you gave it to me in a few mins thank you so much


Sorry for my poor english

Glad I could help, good luck with what you’re working on.

Thank you.