Question by
DeVoxi · May 18, 2017 at 12:36 AM ·
unity 5uibuttongui-button
How do I make a UI button imitating mouse click
I need to make buttons on screen. I tried to do buttons like this "GUI.Button(new Rect(10, 70, 50, 30), "Click")" but making it responsive is really difficult for me. I need to make UI buttons (theese in Canvas) imitating mouse click/normal button. This is the code:
public float direction = 1;
void Update () {
Rigidbody rigidbody = transform.GetComponent<Rigidbody>();
if (Input.GetKey(KeyCode.LeftArrow))
{
direction = 0;
}
if (Input.GetKey(KeyCode.RightArrow))
{
direction = 1;
}
if (direction == 1)
{
rigidbody.AddTorque(0, 90, 0);
}
if (direction == 0)
{
rigidbody.AddTorque(0, -90, 0);
}
}
}`
Comment
Your answer
Follow this Question
Related Questions
Can i update button listener? 0 Answers
Can't access functions on my UI button 1 Answer
is it possible to have two on click events in one button 1 Answer
How to create a back button? 0 Answers