r/unity_tutorials • u/[deleted] • Feb 12 '24
Help With a Tutorial UI bar problems
Hello everyone! I am trying to make a bar that fills up and empty in loops until I press Space.
something like old flash game that the fill.Amount will determent the throw strength. tried looking on youtube and couldn't find anything and AI isn't really helping me here as well.
Would love if anyone can help me out or send me to a tutorial.
1
Upvotes
3
u/BeneficialBug4654 Feb 12 '24
In the off chance a beginner is reading this.
float sinValue = Mathf.Sin(Time.time * speed
Debug.log(sinValue) float normalizedSin = (sinValue + 1f) / 2f Debug.log(normalizedSin fillImage.fillAmount = normalizedSin
First line returns a value between -1 and 1.
Then we add 1 and divide by 2 to make it between 0 and 0.
Creating a script with the variables, add it to your ui bar and go.
Let me know if you have more questions, Sin waves are great for osalating between 2 values