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 nick9629 · Jun 18, 2012 at 09:13 AM · guibuttons

I want to move my cube using GUI buttons?

i want to move my cube in a train on Move Front, back, right and Left GUI Buttons by pressing them?

Comment
Add comment · Show 2
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 Mizuho · Jun 18, 2012 at 09:15 AM 1
Share
 if(GUI.Button(new Rect(#, #, #, #), "Front") {
     // Add code for "$$anonymous$$ove Front" here
 }
 if(GUI.Button(new Rect(#, #, #, #), "Back") {
     // Add code for "$$anonymous$$ove Back" here
 }
 if(GUI.Button(new Rect(#, #, #, #), "Left") {
     // Add code for "$$anonymous$$ove Left" here
 }
 if(GUI.Button(new Rect(#, #, #, #), "Right") {
     // Add code for "$$anonymous$$ove Right" here
 }

All in OnGUI(), of course.

avatar image nick9629 · Jun 18, 2012 at 09:34 AM 0
Share

thanks for reply, can u also tel me the script for move forward

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by hijinxbassist · Jun 18, 2012 at 09:33 AM

If this is on your cube, you can use this version. Otherwise change transform.position to cube.position(if you declaration is : Transform cube)

 if(GUI.Button(new Rect(#, #, #, #), "Front") {
    transform.position+=transform.forward;
 }
 if(GUI.Button(new Rect(#, #, #, #), "Back") {
    transform.position-=transform.forward;
 }
 if(GUI.Button(new Rect(#, #, #, #), "Left") {
    transform.position-=transform.right;
 }
 if(GUI.Button(new Rect(#, #, #, #), "Right") {
    transform.position+=transform.right;
 }

This will move them one gameUnit: (0,0,1) or (0,0,-1) or (-1,0,0) or (1,0,0)

If you want to move them holding the button down you can use RepeatButton.

Comment
Add comment · Show 4 · 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 Mizuho · Jun 18, 2012 at 09:58 AM 0
Share

@nick9629: Could you accept his answer so this question closes?

avatar image hijinxbassist · Jun 18, 2012 at 10:08 AM 0
Share

@$$anonymous$$izuho LOL, somehow i missed the original question and only saw your comment! Didnt mean to jack your post(word for word), thot it was the org at a glance. Thanks for your help previous and your support here, thanks

avatar image Mizuho · Jun 18, 2012 at 10:09 AM 0
Share

@hijinxbassist: That's completely awesome xD. Answered the question because you thought my answer was the question xD.

avatar image hijinxbassist · Jun 18, 2012 at 10:13 AM 0
Share

Pretty funny indeed, the question was soo short i skipped right over the question(not usual) and just read the code(normally the first thing i read in a post, after skim$$anonymous$$g the concern)

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

Control script generated buttons with a Gamepad 0 Answers

How can i design 3d buttons in unity 3d? 1 Answer

On Screen Button Controls 0 Answers

Stuck with sliding GUI panels 0 Answers

Problem with rect and touch 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