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 Rekaens · Jun 12, 2012 at 11:53 AM · guimovementtime

how do i make this move slowly over time

i got this problem where i have my GUI labels and i want to as soon as you hit new game, the menu will slide off to the left wich is -600 but i simply cannot find a way to do it :/ any wise heads out there? thanks alot in advance!

 void OnGUI() {
     GUI.skin = menu_styles;
     if (main == true){
         GUI.BeginGroup(new Rect(placeing, 0, 800,900));
             if (GUI.Button(new Rect(0, 40, 512, 128),"",menu_styles.customStyles[0])){
                     //main = false;
                     //placeing = (-600f) * Time.deltaTime;
                     placeing = BLANK
                 Debug.Log ("lol");
             }
             
             if (GUI.Button(new Rect(0, 170, 512, 128),"",menu_styles.customStyles[1])){
                 
             }
             
             if (GUI.Button(new Rect(0, 300, 512, 128),"",menu_styles.customStyles[2])){
                 
             }
             
             if (GUI.Button(new Rect(0, 430, 512, 128),"",menu_styles.customStyles[3])){
                 
             }
         GUI.EndGroup();
     }
 }
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by aldonaletto · Jun 12, 2012 at 12:26 PM

You could have a destX variable holding the desired X coordinate and make placeing moves gradually to it:

public float speed = 800; // speed in pixels/second public float destX = 0; // set the desired X coordinate here

void Update(){ // slide placeing towards destX at Update placeing = Mathf.MoveTowards(placeing, destX, speed * Time.deltaTime); ... }

void OnGUI() { GUI.skin = menu_styles; if (placeing > -600){ // only draw the GUI when menu not completely hidden if (main == true){ GUI.BeginGroup(new Rect(placeing, 0, 800,900)); if (GUI.Button(new Rect(0, 40, 512, 128),"",menu_styles.customStyles[0])){ destX = -600; // sets the new destX to start sliding } // other buttons GUI.EndGroup(); } } } Just set destX to 0 to make the menu slide in, and click the button to make it slide out.

Comment
Add comment · Show 2 · 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 Rekaens · Jun 12, 2012 at 05:59 PM 0
Share

thanks!!! it worked with 1 tweek, how come i cannot use time.deltatime? i have to use time.time?? if i use time.deltatime nothing happens :( know why that is?,thank you! it worked but i cannot use delta time?? i had to use Time.time?? why is that? time.deltatime didnt do anything at all

avatar image aldonaletto · Jun 13, 2012 at 12:31 AM 0
Share

Have you changed something? Notice that $$anonymous$$oveTowards must be in Update, not in OnGUI.
$$anonymous$$ultiplying speed by Time.deltaTime makes the movement independent of the framerate. If you omit the multiplication, the menu will move speed pixels each frame - and the framerate may vary a lot during the game or among different machines.
NOTE: I forgot to specify the speed type: it should be declared as a float (answer already fixed). If C# decided it's an int (or if you declared it as an int), the function will not work with Time.deltaTime, as you've said. Declare speed as a float, and maybe your problem magically disappears:

 public float speed = 800; // speed in pixels/second

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Movement script stops working when time.timescale= 0 1 Answer

How to WaitforSeconds a GuiButton ? 0 Answers

How to create an agenda or timetable system? 1 Answer

Showing Time With GUI.Label 1 Answer

How to Follow By Getting KeyDown? 0 Answers


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