Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by Gaming Worlds · Jan 13, 2016 at 03:23 AM · scripting problemmovementbutton

Make button move character?

So I have a button on the screen. I want the button to move the character whenever its pressed.

Here's the code i have so far

 public void left(string leftcircle) {
 
             GetComponent<Transform> ().RotateAround (Vector3.zero, Vector3.forward, -xRotate);   //= Quaternion.Euler (0, 0, xRotate); 
             
 
     }

This is attached to the button so obviously whenver it is pressed, the actual button moves. So is there a way to tell it to move the object and not the actual button?

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
Best Answer

Answer by UniqueMAX · Jan 13, 2016 at 03:51 AM

Attach the script to the object you want to move, not to the button. Then choose your button, in its options find the OnClick() box, press "+". The line consisting of an input field will appear. Drag and drop the object to this field, then click the combobox to the right from the field and find a line that's called "left".

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 Gaming Worlds · Jan 13, 2016 at 03:58 AM 0
Share

@Unique$$anonymous$$AX

Thanks for the quick answer!

Quick question though. Is there a way to make it that when you press and hold the ubtton, the character rotates. Because right now, when you press it the object only moves a little bit. So now you have to keep pressing the button repeatedly, but I just want it to be held down.

avatar image UniqueMAX Gaming Worlds · Jan 13, 2016 at 04:33 AM 1
Share

I don't know for sure. I could only suggest another mechanics: You press the button once and object starts rotating continuosly. You press it again and it stops. If that fits your requirements I can post code sample. For hold function you should search more

avatar image Gaming Worlds UniqueMAX · Jan 13, 2016 at 04:42 AM 0
Share

No that wouldn't work for the game. Since I'm porting this to a touch device. Is it possible to add a sprite with box collider and when the player touches inside the sprite, the rotation begins?

Show more comments

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

38 People are following this question.

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

Related Questions

Isometric Movent Issue 0 Answers

my wasd is not linking with my camera, can anyone help?,My Camera is not syncing with my wasd movement, can anyone help? 0 Answers

Stop movement on collision 1 Answer

How to create buttons with script? 0 Answers

UI Button Movement Problem 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