How to make an Auto Slider C#
So i am trying to make a game similar to AdVenture Capitalist. So i cant seem to figure how to make those progres bars in order to gain money. Does anyone have any suggestions?
Assu$$anonymous$$g not everyone is familiar with that game or knows what an "auto slider" is, can you explain the actual functionality ins$$anonymous$$d, please? You are unlikely to receive an answer that gives you a full implementation, but we could set you on the right track with a bit more detail.
@$$anonymous$$TheDev I just learned that it is called a progress bar. I want to make something like that, but i have no clue how. I want to know how to make it go till the progress bar fills up then goes back and when it fills up, i get the money that the progress bar rewards me.
Does it fill in live or does it depend on time?
Answer by Firedan1176 · Sep 21, 2015 at 09:55 PM
You could use a slider and make some modifications to the material. The important part is changing the value. You could create a reference to the slider such as Slider mySlider = GetComponent<Slider>();
. Then, you can change the value based on your progress by setting the value
of the slider:
mySlider.value = someFloatValue;
If you would like to create a percentage progress bar, you can set the slider's max value to 1. You can then divide the current float value by the maximum to get a percentage, and set the slider's value from that. Something like this:
float somePercent = 6f; //50% of 12
Slider mySlider = GetComponent<Slider>();
void Start() {
mySlider.value = somePercent / 12f; //assuming that somePercent has a max value of 12
}
After this, you can set the interactable of the Slider to false, so it is really just a visual element. Then modify some textures, and boom! Good luck. Let me know if you need more explaining.
@Firedan1176 so like this: using UnityEngine; using System.Collections;
public class Slider : $$anonymous$$onoBehaviour {
public float value = somepercent;
float somePercent = 6f; //50% of 12
Slider mySlider = GetComponent<Slider>();
void Start() {
mySlider.value = somePercent / 12f; //assu$$anonymous$$g that somePercent has a max value of 12
}
}
@Firedan1176 ok so i still haven't figured anything out here is my skype so we can do this a lot easier.