- Home /
The question is answered, right answer was accepted
Trouble implementing movement with a Button
Hello Everyone!
I want to know if there is a way where I can move my player by pushing an UI Button.
Most of the examples I find, come with a different implementation of how to move the character.
Mine is just a simple conditional like this:
if (Input.GetKey("d") || Input.GetKey("right") ) /////MOVING RIGHT
{
rb2d.velocity = new Vector2(speed, rb2d.velocity.y);
animator.Play("player walk right");
}
I thought adding the button would have been as simple as finding a way to link it to the input.getbuttondown and just add it to the IF condition, but I have not been able to find a way to do this anywhere.
Like this:
if (Input.GetKey("d") || Input.GetKey("right") ||Input.GetButtonDown("myButton") ) /////MOVING RIGHT
Any ideas on how I can implement this? My main goal is to have a button on screen that I can push on the cellphone and move the character.
After searching the whole day, I was able to find a way to implementing. Guess I have to search better.
Here is the link to the youtube video: https://www.youtube.com/watch?v=S8QNZ7oWXqw