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
0
Question by pborg · May 22, 2012 at 06:36 AM · animationbuttons

How to make buttons move

I'm building a japanese study game and using buttons as the primary mode of movement between scenes. I'm working on a fade in. How do you make buttons move in from the sides?

Comment
Add comment · Show 4
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 save · May 22, 2012 at 06:37 AM 0
Share

Are they GameObjects or GUI-buttons?

avatar image Reavenk · May 25, 2012 at 04:24 AM 0
Share

Store a Vector2 variable that interpolates from off-screen to in-screen in screenspace coordinates, in the Update() function. Then in the OnGUI() function, use that variable to position the button.

avatar image Kiloblargh · May 25, 2012 at 03:02 PM 0
Share

All of my buttons are 3d objects parented to my camera, and all my UI text are text meshes. I move them around like I'd move around anything else. There must be some benefit to using the 2d GUI functionality- since most people do- but I'm not seeing it, and I seem to be avoiding a lot of the scaling and positioning problems that others have.

avatar image You! · May 25, 2012 at 03:04 PM 0
Share

@Unitard That sounds like an answer. Please convert your comment to an answer so you can get more credit for it!

3 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by You! · May 25, 2012 at 04:45 AM

Make a variable which changes as you want the button to move, and have the button appear off-screen. Here is an example (in Javascript).

 var buttonx : int = -100
 var buttony : int = 200
 // [...]
 function OnGUI ()
 {
 if(GUI.Button(Rect(buttonx,buttony,100,200),"Some text is here..."))
 {
 //Whatever the button does is here.
 }
 }

The coding for however you want the button to move is elsewhere in the script. This is done by changing the values of buttonx and buttony in any way you want until you reach the button's destination.

To change the position of the button, continually change the value of buttonx and buttony in the Update() function, like you mentioned below. Here is an example:

 function Update()
 {
 if (buttonx < 100)
 {
 buttonx += 5 //Move the button 5 pixels per frame to the right until it reaches its destination (100).
 }
 if (button y < 300)
 {
 buttony += 5 //Move the button 5 pixels per frame downward until it reaches its destination (300).
 }
 }
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 pborg · May 25, 2012 at 05:25 AM

Would you then change the buttonx and buttony values in the update function? And how will it make a smooth transition instead of simply moving to the new location?

Comment
Add comment · Show 1 · 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 hijinxbassist · May 25, 2012 at 05:28 AM 1
Share

Please use the comment button for comments. If it does not show up, navigate back to your user profile and click on your question(this should reset the buttons). Thanks

avatar image
0

Answer by pborg · May 25, 2012 at 05:34 AM

Would you then change the buttonx and buttony values in the update() function? How do you move it smoothly rather than simply jumping to the new coordinates?

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 You! · May 25, 2012 at 02:51 PM 0
Share

I updated my answer to the question. Also, please post comments using the "add new comment" button under an answer or a question, as @hijinxbassist suggested. It makes the question post clearer when it comes to others finding answers.

avatar image pborg · May 25, 2012 at 06:56 PM 0
Share

I couldn't see the comment I made, so I double posted. sorry

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

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Can I make animations snap to a frame? 1 Answer

How do I get my UI Button to play my "fire animation" once? 2 Answers

Having trouble with button animation 0 Answers

Using one animation on multiple objects? 1 Answer

How to select an animation clip by index number? 7 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