How to move 2d gui items smooth

Hi,

I have searched unity forum but could not find any helpful link about it. How can we move smoothly the 2d GUI buttons in menu from one point to an other.

thanks

unitylearner

I wish to slide my buttons like in this video when we press play button it goes to a sliding menu…

any idea to implement this.?

thanks

Try

GUI.matrix = [URL="http://unity3d.com/support/documentation/ScriptReference/Matrix4x4.TRS.html"]Matrix4x4.TRS[/URL](new Vector3(xOffset, yOffset, 0f), Quaternion.identity, Vector3.one);

i have three buttons… I could not utilize GUI.matrix for those three buttons.

it might be easy… but sorry I could not understand its usage. could you guid how to use it for GUI.Button()?

thanks for reply

Just set it with the desired offset before you draw each button. Set it to Matrix4x4.identity afterwards if you want to draw normally.

Why don’t you just translate them across, just like in 3D space, but with really small increments.
transform.Translate
Then either translate off screen or put an if statement to stop them somewhere on screen.

sorry i was away

@samshosho how can we implement transform.Translate on 2d GUI Button, as it is made for transform?

sorry this may be silly question. I have been using unity months ago. I am just starter.

thanks

use an Update() function and create a flag to active it… :
(let´s´say you want to move your gui DrawTexture on X axis, start pixel is 0, end pixel is 550)…

var myTexture : Texture2D;
static var guiElementXPos : int;
static var moveGUIElement : boolean = false;

function OnGUI(){
var myButton = GUI.DrawTexture(Rect(guiElementXPos, 0, 50, 50),  myTexture, ScaleMode.StretchToFill, true, 0.0f);

if (myButton){
   moveGUIElement = true;
   }
}

function Update(){
if (moveGUIElement){
  guiElementXPos += 2;
  if (guiElementXPos == 550){
     moveGUIElement = false;
     }
  }
}

Try this:

http://www.unifycommunity.com/wiki/index.php?title=GUIFly