How to Make a Scroll In Menu

I have made a horizontal window with a GUT Texture I made in Photoshop (my menu). I want to menu to scroll in from the bottom when the user presses “m”. I have code right now that allows the menu to pop up on the screen when the user presses “m” but I want it to scroll in from the bottom.

Any ides?

i mostly use 3d objects and texts so i don’t try to code.

But i can deliver pseudo code and the theory to achive this :wink:

you need 5 variables:

var activePosition : float = 300; // you have to play with all of this of cause
var inactivPosition : float = -100;
var isActive : boolean = false;
var scrollSpeed : float = 100;
var menuPosition

than you need this functions:

function changeMenuState()
		//turn the gui visible here
		//now scroll it in
		isActive = true;
		while(menuPosition < activPosition)
			menuPosition += scrollSpeed*Time.deltaTime;
			yield WaitForEndOfFrame;
		//scroll it off
		isActive = true;
		while(menuPosition > inactivPosition)
			menuPosition -= scrollSpeed*Time.deltaTime;
			yield WaitForEndOfFrame;
		//turn gui invisible	

your gui function schould look like this:

function OnGUI () {
	if (GUI.Button (Rect (10,menuPosition,150,100), "I am a button"))
		print ("You clicked the button!");

you ned to call the function by pressing “m”
just typed it down , so could be optimized but should do the job :wink:

I recommend learning about the Mathf.Lerp function.

This function allows you to blend a value (a float, a vector, an angle) between a start and finish value.

You can use this function to lerp the position of the menu from the bottom of the screen to its final position (and vice versa).

We use the following approach to animate our menus on and off the screen:

  1. store the time when the animation begins (for example, set a variable to Time.time when a button is pressed)
  2. keep track of how long it's been since the animation began (current time minus begin time)
  3. choose how long you want your animation to last (1.4 seconds for example)
  4. determine the lerp factor (a ratio between 0 and 1 that represents where we are in the animation). this should equal the time since the animation began divided by the animation duration (step 3).
  5. use the Lerp function to blend your menu's position (in your case you would set the y-coordinate of your menu to the output of the lerp function)

You would ultimately have some code that looks like this:

/* how long should the animation last in seconds */

var animationDuration : float = 1.4f;

/* the final position of the menu (y-coordinate in this example) */

var finalPosition     : float = 200;

var timeSince  =  Time.time - animationStartTime;

var lerpFactor =  timeSince / animationDuration;

var menuY = Mathf.LerpAngle(0, finalPosition, lerpFactor);

This example would blend the value of menuY between 0 and 200 over the course of 1.4 seconds. It assumes that the value of animationStartTime gets set somewhere else in the code when the animation is supposed to begin (presumeably when a button is clicked).

Hope this helps!