Making iTween work with OnGUI functions

Hi, I've just downloaded iTween and have been playing around with it. At the moment, I'm trying to animate GUI buttons but not sure how to approach it. I've tried using:

`
...
if (GUI.Button (Rect (310,40,280,20), "First Button")) {
        print("Do somethin");
        iTween.ValueTo(myGUI, {"from":(Rect(310,40,280,20)), "to":(Rect(250,20,120,10)), "onUpdate":"myButton"});
    }

function myButton(Rect){ print("myButton"); }

` It didn't have any errors but nothing is happening. Hope someone can help.

Thanks in advance. -Hakimo

You can try

if(GUI.Button(Rect(x,y,280,20), "First Button"))
{
     iTween.MoveTo(myGUI, {"x": 250, "y":20,});
} 

By setting the GUI.Button x and y value to a variable, you can then move the GUI Button with the script. Hopefully this is what you wanted.

If you are looking to animate GUI elements I would recommend using the tweening engine LeanTween instead. It makes this task very easy. Here is an example of how you can tween a button with very little code:

// Javascript Code
private var bRect:LTRect = new LTRect( 0, 0, 100, 50 );
function OnGUI(){
 if(GUI.Button(bRect.rect, “Scale”)){
  LeanTween.scale( bRect, Vector2(bRect.rect.width, bRect.rect.height) * 1.3, 0.25 );
 }
}
// C# Code
private LTRect bRect = new LTRect( 0f, 0f, 100f, 50f );
void OnGUI(){
 if(GUI.Button(bRect.rect, “Scale”)){
  LeanTween.scale( bRect, new Vector2(bRect.rect.width, bRect.rect.height) * 1.3f, 0.25f );
 }
}

You can find more detailed examples of how to tween GUI Elements here: http://dentedpixel.com/developer-diary/animate-unity-gui-elements-with-ease/

Hi Hakimo, I suggest this:

var buttonRect : Rect = Rect(pos.x,pos.y,width,height);

GUI.Button(buttonRect, "Text");

iTween.ValueTo(myGUI, {"from",(Rect(310,40,280,20)), "to",(Rect(250,20,120,10)),"onupdate","myButton","onupdateparams","Rect","time",1,"easetype","spring"});

function myButton(size : Rect){
    buttonRect = size;
}
// Check the syntax use "," rather then ":" for the values 

This way you can manipulate the size and position of your GUIButton, you need to use the Rect value from the iTween (from, to), I have the same problem many days a go.

Hopes this help to you, have a great programming day.