Moving GUI Button (or Box)?

So what I want is move GUI element from start position to end position in GUI screen coordinate.

I wrote like this but does not work. What’s the problem?

 var start : Vector2;  // set to 0,0
 var end : Vector2;   // set to 100, 100
 private var pos : Vector2;
  
 function OnGUI(){
  GUI.Box(Rect(pos.x, pos.y, 50, 50), "Hello"); 
  pos.Lerp(start, end, Time.deltaTime * 2); 
 }

pos.MoveTowards also does not work.

Arg!

Never put movement code inside a OnGUI() - because you don’t know how many times it will be called!

Here’s a sample script:

 var start: Vector2; // set to 0,0
 var end: Vector2 = Vector2(100, 100); // set to 100, 100
 var speed: float = 1;
 
 var currentPos: Vector2;

 function Start() {
     currentPos = start;
 }

 function OnGUI() {
     GUI.Box(Rect(currentPos.x, currentPos.y, 50, 50), "Hello");
 }

 function Update() {
     currentPos = Vector2.Lerp(currentPos, end, Time.deltaTime * speed);
 }

You can make some thing like this :

var y : float = 0;

function Update()
{
if(y<=100)
y+=Time.deltaTime+50; // Adjust the Speed here with your values
}

function OnGUI()
{
GUI.Box(Rect(Screen.width/2+y, Screen.hight/2, 50, 50), “Hello”);
}

works well