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 Addyarb · Jan 26, 2015 at 04:28 PM · uibutton

Rotate character with button hold in uGUI?

Hi there Unity!

Still getting used to the uGUI system, but it looks like there's only "On Click" as far as functions go. I want to rotate a character model (Sort of like in WoW where you can view your character's equipment and rotate him around) by pressing left or right arrows buttons. The problem is, there's not really a way to detect if the button is down, and setting a bool to true after detecting mouse-down isn't an option, since the "On Click" function only begins when you release the mouse.

Any help is greatly appreciated.

Thanks!

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 Mmmpies · Jan 26, 2015 at 04:33 PM

Just add an event trigger and the Click the add button that appears, should be called something like PointerDown.

A slot will appear for you to drag an object onto all you need is a script with a public function to handle the rotation and set it just as you would with OnClick.

Sorry not got access to Unity ATM so descriptions a bit vague.

EDIT

OnPointerDown and it'll work for any UI element youu just drag the game object with your script attached to it onto the slot and from the dropdown to the side select YourScriptName -> YourPublicFunctionName.

You can also do this with a button click, have the public function set a bool to equal the opposite of itself.

 public void BeenClicked()
 {
    myBool  = !myBool;
 }

So you button goes from off to on and back with each click, but as you wanted it held OnPointerDown will work for you.

EDIT 2

and this is an event trigger so Add Component Event Trigger not the onclick but event triggers all work pretty much the same as OnClick, they're just triggered by different actions.

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 Addyarb · Jan 26, 2015 at 04:35 PM 0
Share

Thanks for the answer. I don't see a "Pointer Down" option. Is this something I need to code as a public function and then attach to the "On Click" area of the button script? If that's the case, I don't think that'd work since the button only detects mouse-up input.

avatar image Addyarb · Jan 26, 2015 at 04:47 PM 0
Share

Perfect, I just needed the event trigger! Thanks for your help. :)

avatar image Mmmpies · Jan 26, 2015 at 04:56 PM 0
Share

No problem, you'll want a OnPointerUp to stop the rotation as well. Very impressed with the Event System though, mighty powerful thing it is.

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

20 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

Related Questions

Simulate Button presses through code unity 4.6 GUI 4 Answers

Adding child to Canvas 1 Answer

uGUI UI Button onclick static methods 3 Answers

Interact with uGUI button using code? 1 Answer

Get/Set Button Text with uGUI 4.6 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