x


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?

more ▼

asked Mar 24 '11 at 10:19 AM

Robbert Bruggeman gravatar image

Robbert Bruggeman
3 1 1 1

(comments are locked)
10|3000 characters needed characters left

3 answers: sort oldest

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");
}
more ▼

answered Mar 24 '11 at 11:03 AM

Statement gravatar image

Statement ♦♦
20.1k 35 70 175

Yes but I have no idea how

Mar 24 '11 at 11:05 AM Robbert Bruggeman

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

Mar 24 '11 at 11:33 AM Statement ♦♦

Then what is this site for?

Mar 24 '11 at 11:37 AM Robbert Bruggeman
(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered Mar 24 '11 at 11:14 AM

Robbert Bruggeman gravatar image

Robbert Bruggeman
3 1 1 1

(comments are locked)
10|3000 characters needed characters left

Is it possible to do without using time

more ▼

answered Mar 24 '11 at 11:35 AM

Robbert Bruggeman gravatar image

Robbert Bruggeman
3 1 1 1

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3680
x3456
x42
x21
x17

asked: Mar 24 '11 at 10:19 AM

Seen: 1213 times

Last Updated: Mar 24 '11 at 10:19 AM