Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by msnowai · Nov 02, 2011 at 08:48 PM · guilerpmenuanimategui-window

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?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by jahroy · Nov 02, 2011 at 10:19 PM

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!

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by CreativeStorm · Nov 02, 2011 at 09:28 PM

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 ;)

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()
 {
     if(!isActive)
     {
         //turn the gui visible here
         //...code...
         //now scroll it in
         isActive = true;
         while(menuPosition < activPosition)
         {
             menuPosition += scrollSpeed*Time.deltaTime;
             yield WaitForEndOfFrame;
         }
     }
     else
     {
         //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 ;)

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image CreativeStorm · Nov 02, 2011 at 09:29 PM 0
Share

var menuPosition needs to be a float as well ;)

avatar image msnowai · Nov 04, 2011 at 08:44 PM 0
Share

in the function onGUI why do i need that print "you clicked a button"??

avatar image john-essy · Nov 04, 2011 at 10:05 PM 0
Share

You don't need it, It's there so you know the code is working so when you press the button, in the DebugLog a message will appear saying You clicked the button

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Animate buttons on click. 2 Answers

Game Menus WIth Keyboard Input Control 1 Answer

Mouse slingshot to touch control problem 0 Answers

How to make a simple menu button with C Sharp 1 Answer

How to make a scrollable menu like angry bird? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges