- Home /
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!
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.
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.
Perfect, I just needed the event trigger! Thanks for your help. :)
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
Follow this Question
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