Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by megalightdev · Mar 28, 2019 at 01:16 AM · timetimer countdownprogress-bar

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.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

168 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges