Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
This question was closed Jun 24, 2016 at 09:45 PM by El-Deiablo for the following reason:

The question is answered, right answer was accepted

avatar image
-1
Question by El-Deiablo · Jun 23, 2016 at 08:49 PM · timertimer countdownfillrate

Make Fillamount Match Timer

I have been working on this for days and cannot perfect it! I looked at the unity manual, checked answers, watched tutorials, and tried multiple codes with no success.

I have a timer working for my powerups, but I want a radial fill bar to accompany the timer. I can get the fill bar to decrease, but the fill bar finishes before the timer runs out (around 5-7 seconds before). What am I doing wrong or what do I need to add to make this work? I'd appreciate any help!

Here's my code:

 using UnityEngine;
 using System.Collections;
 using UnityEngine .UI;
 using UnityEngine .SceneManagement ;
 
 public class PowerUpTimer : MonoBehaviour {
 
     public Text timer;
 
     public Color slowDownColor;
     public Color goldToothColor;
     public Color X2Color;
 
     float goldToothTimeAmt;
     float multiplierTimeAmt;
     float slowDownTimeAmt;
 
     public Image goldToothFillImg;
     public Image multiplierFillImg;
     public Image slowDownFillImg;
 
     private float doneTime = 1f;
     private float maxTime;
 
     // Use this for initialization
     void Start () {
 
         goldToothFillImg.enabled = false;
         multiplierFillImg.enabled = false;
         slowDownFillImg.enabled = false;
 
         /*goldToothTimeAmt = GoldToothPowerUp .time ;
         multiplierTimeAmt = Multiplier.time;
         slowDownTimeAmt = TimeChangingPowerUp.time;*/
 
         timer.GetComponent <Text> ();
         timer.enabled = false;
 
     }
     
     // Update is called once per frame
     void Update () {
 
         if (SceneManager.GetActiveScene ().name == "Buck Bite Tyson GameOver Scene") {
 
             timer.enabled = false;
 
         }
 
         if (Multiplier.Active == true) {
 
             //maxTime = 20f;
             multiplierFillImg.enabled = true;
             multiplierFillImg.fillAmount -= 1.0f / Multiplier.time * (Time.deltaTime*0.6f);
             timer.enabled = true;
             Multiplier.time -= Time.deltaTime;
             //multiplierFillImg.fillAmount -= (Time.deltaTime / (Multiplier.time));
             //multiplierFillImg.fillAmount -= (Multiplier.time/Time.deltaTime);
             //multiplierFillImg.fillAmount -= ((doneTime / maxTime)/Time.deltaTime );  
             timer.text = Multiplier.time.ToString ("f0");
             timer.color = X2Color;
 
 
         }
 
         if (Multiplier.time <= 0) {
 
             multiplierFillImg .enabled = false;
             Multiplier.Active = false;
             Multiplier.time = 20f;
             timer.enabled = false;
 
         }
 
         if (GoldToothPowerUp .Active == true) {
 
             //maxTime = 10f;
             goldToothFillImg.enabled = true;
             goldToothFillImg.fillAmount -= 1.0f / GoldToothPowerUp.time * (Time.deltaTime*0.6f);
             timer.enabled = true;
             GoldToothPowerUp .time -= Time.deltaTime;
             //goldToothFillImg.fillAmount -= (Time.deltaTime / (GoldToothPowerUp.time));
             //goldToothFillImg.fillAmount -= (GoldToothPowerUp.time/Time.deltaTime);
             //goldToothFillImg.fillAmount -= ((doneTime / maxTime)/Time.deltaTime );
             timer.text = GoldToothPowerUp .time.ToString ("f0");
             timer.color = goldToothColor ;
 
         }
 
         if (GoldToothPowerUp .time <= 0) {
 
             goldToothFillImg.enabled = false;
             GoldToothPowerUp.Active = false;
             GoldToothPowerUp.time = 10f;
             timer.enabled = false;
 
         }
 
         if (TimeChangingPowerUp .Active == true) {
 
             //maxTime = (20 * Time.deltaTime);
             slowDownFillImg.enabled = true;
             slowDownFillImg.fillAmount -= 1.0f / TimeChangingPowerUp.time * (Time.deltaTime*0.6f);
             timer.enabled = true;
             TimeChangingPowerUp.time  -= (Time.deltaTime/TimeChangingPowerUp.speed) ;
             //slowDownFillImg.fillAmount -= ((Time.deltaTime / TimeChangingPowerUp.speed) / (TimeChangingPowerUp.time));
             //slowDownFillImg.fillAmount -=  (TimeChangingPowerUp.time/Time.deltaTime);
             //slowDownFillImg.fillAmount -= ((doneTime / maxTime)/Time.deltaTime );
             timer.text = TimeChangingPowerUp.time .ToString ("f0");
             timer.color = slowDownColor ;
 
 
         }
 
         if (TimeChangingPowerUp.time <= 0) {
 
             slowDownFillImg.enabled = false;
             TimeChangingPowerUp.Active = false;
             TimeChangingPowerUp.time  = 20f;
             timer.enabled = false;
 
         }
 
     }
 }

 
Comment
Add comment · Show 1
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
avatar image Habitablaba · Jun 23, 2016 at 08:52 PM 0
Share

You asked this exact question yesterday. In fact, at the time of clicking into this version of the question, your other question was only 2 down on the front page. Please refrain from opening multiple questions asking the same thing.

1 Reply

  • Sort: 
avatar image
1

Answer by DroidifyDevs · Jun 23, 2016 at 09:54 PM

Please do not post the same question multiple times. It isn't good ethics and clutters the website. Your original question has plenty of good answers. Eventually you might get banned by a moderator.

This is what I do to make fillable bars: https://www.youtube.com/watch?v=XTFL4IZnkMk

Simply have a ratio of time do the fill amount. For example:

 public float TimeRatio;
 
 TimeRatio = TimeLeft / TotalTime;

Then use that ratio for the fill amount (shown in the video attached).

Comment
Add comment · Share
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

Follow this Question

Answers Answers and Comments

47 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

Related Questions

Timer Progress Bar 2 Answers

Start countdown timer with condition 1 Answer

Create a little time pause just after jumping 2 Answers

Save Time Button Settings in Player Prefs 2 Answers

How do you make a countdown timer that will lose time if you press a button? 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