hey guys, I’m pretty new at using the complex GUI system. I want to animate a button falling into place, but I have no idea how to begin doing this. Here is my button code:
(GUI.Button(new Rect(50, 50, 72, 72), "", m_ButtonStyle))
OnButtonClick();
hey guys, I’m pretty new at using the complex GUI system. I want to animate a button falling into place, but I have no idea how to begin doing this. Here is my button code:
(GUI.Button(new Rect(50, 50, 72, 72), "", m_ButtonStyle))
OnButtonClick();
I guess I would set a very low value for the y value of the Rect (even below 0), and increment it to the normal position.
Use Mathf.Lerp. to achieve that.
Thank you AkilaeTribe!
Yes, I looked at using some sort of Lerp, but how exactly do I apply it to the GUI.Button? I’m really new to coding…
Alternately, I can have the button sort of grow in size from 0 to 1. Same problem there though, how do I apply the lerp to the GUI.Button function…?
Well, the values in your Rect are not constants, they can change during time.
Rect (x, y, width, height)
y changes from -100 to 10.
y = Mathf.Lerp (-100, 10, percentage);
percentage is a float.
var percentage : float;
When percentage = 0, y = -100
When percentage = 0.25, y = -72.5
When percentage = 0.5, y = -45
When percentage = 1, y = 10
Same goes for your growing problem.
size = Mathf.Lerp (0, 1, percentage)
width = normalWidth * size
Let’s say normalWidth = 100.
When percentage = 0, width = 0
When percentage = 0.25, width = 0.25
When percentage = 0.5, width = 0.5
When percentage = 1, width = 1
Do you understand ?
Thanks for the reply!
I understand mostly. The percentage part sort of confuses me. How do I write it if I want the Lerp to take 1 second? I tried making that variable Time.time, which worked nicely, except it happened immediately, instead of waiting to be triggered.
Any help there?
If you want the Lerp to take one second, you must ensure that its percentage argument goes from 0 to 1 in one second.
ok, and how do I do that? Sorry I’m still new to coding ![]()
At this point, it is clear you should read up on Linear Interpolation and how to use it instead of trying to get people to write your code for you. In the long run, if you practice it and learn it with tiny examples, you will understand it well enough to apply it to multiple problems.
that’s a good point, thanks for all your help, I’ll look into it from here!
If you wanted to see it in purely textual format, you could output a Time function along with the interpolated values. That would really help clear the distractions.