Best way to tween Gui Elements?

Im working right now on my GUI and i want to create a Accordion like Select Menu.

I search for the best way to tween GUI Elements.

Are there any existing scripts wich provide this issue? All i found was the iTween script which only provides GameObjects.

So after thinking about this problem all day long, i came to a solution similar i did with the Tweener Library in FLash sometimes.

Here is the example code "GuiTweenTest.cs":

using UnityEngine;
using System.Collections;

public class GuiTweenTest : MonoBehaviour {

    private GameObject tweenObject;
    // Use this for initialization
    void Start () 
        tweenObject = new GameObject();

    // Update is called once per frame
    void Update () {


    public void OnGUI()
        float xPos = tweenObject.transform.localPosition.x;
        float yPos = tweenObject.transform.localPosition.y;

        if (GUI.Button(new Rect(xPos, yPos, 100, 40), new GUIContent("click me")))
            iTween.moveTo(tweenObject, 1, null, Random.Range(0, Screen.width-100), Random.Range(0, Screen.height-40), null);

What i basically do is, to create a empty GameObject which holds my Gui Element Position, and with this Position container which is a GameObject, i can use the full advantage of the iTween Library.

I hope you like the idea! :)

There are basically three ways to do it.

1) the hard custom way: use something like AniMate and tween properties in your class that does an OnGUI call.

So without writing the code, have a public offset variable, and use AniMate to tween that offset variable, and in your Rect creation for your buttons, use that offset variable.

2) the hard encapsulated way: Instead of using OnGUI in your own classes, write a UI system that encapsulates everything that Unity GUI does that your project needs. The discussion on this is outside the scope of this question, but the way we did it was basically have a UI Manager that had our single OnGUI call, and then had custom classes like UIWindow and UIButton that handled everything themselves. And inside those buttons they would tween themselves like in 1), but you didn't have to worry about it on the client side.

This might be worth while to do if you have a lot of UI elements as it lets you do things like encapsulate click button sounds, etc.

3) the bypass OnGUI since it doesn't really allow for a lot of advanced features way: Instead of using the UnityGUI, perhaps it would be better to do it in 3D. This is basically what EZ GUI does. Or maybe you do it in 3D with an animation and just use the OnMouseDown method on your button gameObjects as if they were UI elements.

Interesting, I like the approach. I'm trying to finish up iTween 2.0 now and I'm trying to find a way to make this even easier with the new version If I figure something better for the next release I'll let you know!

iTween 2.0 will allow you to do generic value tweens iTween.ValueTo() and it can do everything from rects and colors to just float doubles and vectors you combine the with a callback it paves the way for easier GUI animations. Sound good?

There's a new example on the iTween support site which shows how to animate GUI elements: here