- Home /
Implement UI buttons in Input Manager
How can I implement UI buttons in the input manager? For example, how can I replace the key "right" in the input manager with my UI buttons?
Answer by Mmmpies · Feb 22, 2015 at 04:43 PM
Where you have your if(Input... code with a UI button you just create a script and have a public function e.g.
public void MoveRight()
{
// depending on you game do the move code here
// or set a bool to true moveMeRight = true and in Update
// if(moveMeRight)
// Do your code here
}
Then drag that script onto your button, highlight the button and click + in the OnClick area.
A slot appears so drag your button onto it, the button contains the script so in the dropdown select MyScriptName -> MoveRight
You might want different functionality than a click though so you can also Add Component -> Event Trigger
From there you could add a PointerDown event to set that bool I mentioned and PointerUp that calls another function in that script called StopRight to set the bool to false. That way you keep moving right until you lift the pointer.
Your answer
Follow this Question
Related Questions
Problem with onClick.AddListener 1 Answer
Hidden Canvas, doesn't disable interaction with buttons. 1 Answer
How Do I Change UI Text With A Button Click? 1 Answer
Custom Behaivior on highlighting button 0 Answers
Button only works once 1 Answer