Progress bar/countdown with hours, minutes, and seconds?
Hello everyone. I am having some trouble with my code. I am very new to coding(only 2 weeks) and am having trouble with my progress bar and countdown. Below is the script that I am currently using with comments.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ArcaneScript : MonoBehaviour
{
//Script References
public GameManagerScript GMS;
public ArcaneMastery AM;
public Text ArcaneIPC;
public Text ArcaneLevel;
public Text ArcaneCooldown;
public Slider ArcaneBar;
//Arcane per click
public float Arcane = 1;
//Base Arcane per click
public float BaseArcane = 1;
//Arcane Level
public int Arcanelvl = 1;
//Arcane Time
public float ArcaneCD;
//Arcane Max Time
public float ArcaneCDMax = 1.5f;
//Click rate cooldown condition
public bool cooldown = false;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
//minimum slider value
ArcaneBar.minValue = 0f;
//Maximum slider value
ArcaneBar.maxValue = ArcaneCDMax;
//Arcane lvl display
ArcaneLevel.text = "Level:" + Arcanelvl;
//Arcane Cooldown display with hours, min, and seconds
if (ArcaneCDMax >= 60)
{
if (ArcaneCDMax >= 3600)
{
ArcaneCooldown.text = "" + ((ArcaneCDMax - ArcaneCD) / 3600).ToString("##") + "h";
}
else
{
ArcaneCooldown.text = "" + ((ArcaneCDMax - ArcaneCD) / 60).ToString("##") + "m";
}
}
else
{
ArcaneCooldown.text = "" + (ArcaneCDMax - ArcaneCD).ToString("#.0") + "s";
}
//Arcane Influence Per Click display
if (Arcane >= 1000)
{
if (Arcane >= 1000000000000)
{
ArcaneIPC.text = "Influence Per Click: " + (Arcane * 0.000000000001).ToString("#.00") + "T";
}
else
{
if (Arcane >= 1000000000)
{
ArcaneIPC.text = "Influence Per Click: " + (Arcane * 0.000000001).ToString("#.00") + "B";
}
else
{
if (Arcane >= 1000000)
{
ArcaneIPC.text = "Influence Per Click: " + (Arcane * 0.000001f).ToString("#.00") + "M";
}
else
{
ArcaneIPC.text = "Influence Per Click: " + (Arcane * 0.001f).ToString("#.00") + "K";
}
}
}
}
else
{
ArcaneIPC.text = "Influence Per Click: " + Arcane;
}
//Defines what is referenced by slider.
ArcaneBar.value = ArcaneCD;
//starts time when cooldown is in effect
if(cooldown == true)
{
ArcaneCD += Time.deltaTime;
}
//Used for Arcane Mastery to start auto tick
if(AM.ArcaneMaster == true)
{
//Adds time
ArcaneCD += Time.deltaTime;
}
//When slider is full reset to 0 and add Arcane power.
if (ArcaneCD >= ArcaneCDMax)
{
GMS.Influence += Arcane;
ArcaneCD = 0;
}
}
//Parameters for clicking Arcane button.
public void ArcaneClick()
{
//Can only click when cooldown is false.
if (cooldown == false)
{
//Changes cooldown to true to prevent multiple clicks.
cooldown = true;
//Invokes cooldown reset.
Invoke("ResetCooldown", ArcaneCDMax + .01f);
}
}
//changes cooldown back to false so the button can be clicked again.
public void ResetCooldown()
{
cooldown = false;
ArcaneCD = 0;
}
}
I realize that most of my code is irrelevant to the question, but I put it in there in case there is something causing a bug. Right now my slider and countdown timer work and it will display either hours, minutes, or seconds with correct information. I cannot figure out how to display all 3 when the number is in the hours. I have tried a few different techniques but nothing seems to work. Thank you very much in advance for the help.
Your answer
![](https://koobas.hobune.stream/wayback/20220612194422im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Is there a way to calculate elapsed Time in total? (Even when the App is closed etc.) 1 Answer
Where and how should I stop the counter when the while loop is ended ? 0 Answers
Clock doesn't stop when reaches 0.0. Can you help me with this. 1 Answer
Farming game Time management 0 Answers
Making a simple countdown timer 1 Answer