- Home /
The question is answered, right answer was accepted
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;
}
}
}
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.
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).