How do I slide a GUI element from outside the screen above vertically into the screen with JavaScript?

I have a title screen with a logo in GUI.I want the logo to start outside of the screen above and slide it into the screen vertically. How do I accomplish this using JavaScript?

3 Answers

3

You can move coordinates with Vector3.MoveTowards or Vector3.Lerp, and coupled together with a coroutine or Invoke, you can control the timing quite easily.

var position : Rect;

function Start()
{
     position.x = 0;
     position.y = -Screen.height;
     position.width = Screen.width;
     position.height = Screen.height;

     yield WaitForSeconds(1);   
     yield Move(0);
     yield WaitForSeconds(3);   
     yield Move(-Screen.height);
     yield WaitForSeconds(1);   

}

function Move(y : float)
{
     while (position.y != y)
     {
        yield;
        position.y = Mathf.MoveTowards(position.y, y, 250 * Time.deltaTime);
     }
}

function OnGUI()
{
     GUI.Box(position, "Hello");
}

Start by reading the manual. Then try out some tests.

Basically what I want is to move a GUI element to another vertical position. It should be so easy but I can't make it work. I don't think I need to use complicated codes such as Lerp, I don't need to check the time or anything, I just want it to slide down on scene start.

Is it possible to do without using time