I am developing a game using unity3D and I need help making a progress time bar such that on collecting particular items time is added and thus the game continues.
Asked
Active
Viewed 1.6k times
5
-
2You could start here... http://stackoverflow.com/help/how-to-ask – WhiteHat Jul 26 '15 at 12:59
-
1there are lots of example available online for creating progress bar in unity. You should first google around and try to find out which one works in your case. You shouldn't be asking any question without putting any effort to find out, if somebody has already asked something similar and have got answers. – Neeraj Kumar Jul 26 '15 at 15:48
2 Answers
12
Create a UI Image that is of type Filled. Use horizontal or vertical fill depending on your progress bar. Then from inside a script you can manipulate the value of the image. I will give you a very simple c# example. For the rest you can just use google and read the unity scripting API.
public class Example: MonoBehaviour {
public Image progress;
// Update is called once per frame
void Update ()
{
progress.fillAmount -= Time.deltaTime;
}
}

Uri Popov
- 2,127
- 2
- 25
- 43
3
U could use a slider en slider.setvalue
.
Example:
//to use this add first a slider to your canvas in the editor.
public GameObject sliderObject; //attachs this to the slider gameobject in the editor or use Gameobject.Find
Slider slider = sliderObject.GetComponent<Slider>();
float time;
float maxtime; //insert your maxium time
void start(){
slider.maxValue = maxtime;
}
void update()
{
time += Time.deltaTime;
if (time < maxtime)
{
slider.value = time;
}
else
{
Destroy(sliderObject);
//time is over, add here what you want to happen next
}
}

WimJ
- 49
- 2
-
This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post - you can always comment on your own posts, and once you have sufficient [reputation](http://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](http://stackoverflow.com/help/privileges/comment). – Nate Barbettini Oct 03 '15 at 16:32
-
@nate, why so rude? A progressbar is a slider witch is every frame set to ur (relative)value. Just add a slider, fil in the fields in the menu and use slider.setvalue to update it. Its the fastes way to make a progressbar. – WimJ Oct 03 '15 at 16:55
-
No rudeness intended. I flagged this as "not an answer" because it appeared to me to be more appropriate for a comment, rather than an answer. If you can add a code example and explanation, I'll happily upvote. – Nate Barbettini Oct 03 '15 at 17:00