Question by
getComponent · May 07, 2016 at 04:13 PM ·
uimovementbuttonsinput.getaxisgetaxis
Using GetAxis with UI Buttons
Hi, i have a question. Here is a sample of code i want to change for using it with UI Buttons. I am using Input.GetAxis, but there are just keyboard buttons, not UI. Please help me to clear how it can be done.
public float speed = 5f;
private Rigidbody2D rb;
void Awake()
{
rb = GetComponent<Rigidbody2D>();
}
void Update()
{
float xDirection = Input.GetAxis("Horizontal");
Move();
}
void Move()
{
rb.velocity = new Vector3(xDirection * speed, rb.velocity.y, 0f);
}
I can simply change xDirection value to -1f, 0f and 1f, but results are different (no acceleration/deceleration).
P.S: Sorry if sentences are not correct enough, English isn't my native language.
Comment
Your answer
Follow this Question
Related Questions
UI Button Movement Problem 0 Answers
Trouble switching between UI buttons 0 Answers
How to hide x number of button while the button its doing something.. 0 Answers
multiple buttons to open world canvases in vr 0 Answers
button pressing the button next to it?! 2 Answers