# Animating the GUI?

**URL:** <https://discussions.unity.com/t/animating-the-gui/418711>\
**Category:** UI\
**Tags:** IMGUI\
**Created:** [July 21, 2010, 8:30pm UTC](https://discussions.unity.com/t/animating-the-gui/418711 "2010-07-21T20:30:27Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon\_92130381](https://avatars.discourse-cdn.com/v4/letter/a/dc4da7/32.png) [@anon\_92130381](https://discussions.unity.com/u/anon_92130381)\
**Post date:** [July 21, 2010, 8:30pm UTC](https://discussions.unity.com/t/animating-the-gui/418711/1 "2010-07-21T20:30:27Z")

</div>

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:

```auto
(GUI.Button(new Rect(50, 50, 72, 72), "", m_ButtonStyle))
OnButtonClick();

```

---

<div class="post-metadata">

**Author:** ![AkilaeTribe](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/akilaetribe/32/153898_2.png) [@AkilaeTribe](https://discussions.unity.com/u/AkilaeTribe)\
**Post date:** [July 21, 2010, 8:45pm UTC](https://discussions.unity.com/t/animating-the-gui/418711/2 "2010-07-21T20:45:40Z")

</div>

> **[Unity - Manual: IMGUI Basics](https://docs.unity3d.com/Manual/gui-Basics.html)**

> [@](#):
>
> The coordinate system is **top-left** based. Rect(10, 20, 300, 100) defines a Rectangle that starts at coordinates: 0,20 and ends at coordinates 310,120. It is worth repeating that the second pair of values in Rect() are total width and height, not the coordinates where the controls end.

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](http://unity3d.com/support/documentation/ScriptReference/Mathf.Lerp.html). to achieve that.

---

<div class="post-metadata">

**Author:** ![anon\_92130381](https://avatars.discourse-cdn.com/v4/letter/a/dc4da7/32.png) [@anon\_92130381](https://discussions.unity.com/u/anon_92130381)\
**Post date:** [July 21, 2010, 9:05pm UTC](https://discussions.unity.com/t/animating-the-gui/418711/3 "2010-07-21T21:05:15Z")

</div>

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…?

---

<div class="post-metadata">

**Author:** ![AkilaeTribe](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/akilaetribe/32/153898_2.png) [@AkilaeTribe](https://discussions.unity.com/u/AkilaeTribe)\
**Post date:** [July 21, 2010, 9:20pm UTC](https://discussions.unity.com/t/animating-the-gui/418711/4 "2010-07-21T21:20:33Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![anon\_92130381](https://avatars.discourse-cdn.com/v4/letter/a/dc4da7/32.png) [@anon\_92130381](https://discussions.unity.com/u/anon_92130381)\
**Post date:** [July 27, 2010, 3:12pm UTC](https://discussions.unity.com/t/animating-the-gui/418711/5 "2010-07-27T15:12:44Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![AkilaeTribe](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/akilaetribe/32/153898_2.png) [@AkilaeTribe](https://discussions.unity.com/u/AkilaeTribe)\
**Post date:** [July 27, 2010, 3:49pm UTC](https://discussions.unity.com/t/animating-the-gui/418711/6 "2010-07-27T15:49:47Z")

</div>

If you want the Lerp to take one second, you must ensure that its percentage argument goes from 0 to 1 in one second.

---

<div class="post-metadata">

**Author:** ![anon\_92130381](https://avatars.discourse-cdn.com/v4/letter/a/dc4da7/32.png) [@anon\_92130381](https://discussions.unity.com/u/anon_92130381)\
**Post date:** [July 27, 2010, 5:43pm UTC](https://discussions.unity.com/t/animating-the-gui/418711/7 "2010-07-27T17:43:15Z")

</div>

ok, and how do I do that? Sorry I’m still new to coding 🙂

---

<div class="post-metadata">

**Author:** ![JRavey](https://avatars.discourse-cdn.com/v4/letter/j/e19adc/32.png) [@JRavey](https://discussions.unity.com/u/JRavey)\
**Post date:** [July 27, 2010, 5:59pm UTC](https://discussions.unity.com/t/animating-the-gui/418711/8 "2010-07-27T17:59:22Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![anon\_92130381](https://avatars.discourse-cdn.com/v4/letter/a/dc4da7/32.png) [@anon\_92130381](https://discussions.unity.com/u/anon_92130381)\
**Post date:** [July 27, 2010, 6:34pm UTC](https://discussions.unity.com/t/animating-the-gui/418711/9 "2010-07-27T18:34:56Z")

</div>

that’s a good point, thanks for all your help, I’ll look into it from here!

---

<div class="post-metadata">

**Author:** ![JRavey](https://avatars.discourse-cdn.com/v4/letter/j/e19adc/32.png) [@JRavey](https://discussions.unity.com/u/JRavey)\
**Post date:** [July 27, 2010, 6:43pm UTC](https://discussions.unity.com/t/animating-the-gui/418711/10 "2010-07-27T18:43:58Z")

</div>

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.
