I have a good code for my game to move left/right/up/down.I then made on scree controls using some pictures with touch input.The problem im facing is that i cannot move left/right using the buttons.The character is stading in place and i dont know how to solve this please help.
// Check to see if the screen is being touched
if (Input.touchCount > 0)
{
// Get the touch info
Touch t = Input.GetTouch(0);
// Did the touch action just begin?
if (t.phase == TouchPhase.Began)
{
// Are we touching the left arrow?
if (LEFT.HitTest(t.position, Camera.main))
{
float move = Input.GetAxis("Horizontal");
rigidbody2D.velocity = new Vector2(move * MaxSpeed,rigidbody2D.velocity.y);
anim.SetFloat("Speed",Mathf.Abs(move));
facingRight = false;
}
// Are we touching the right arrow?
if (RIGHT.HitTest(t.position, Camera.main))
{
float move = Input.GetAxis("Horizontal");
rigidbody2D.velocity = new Vector2(move * MaxSpeed,rigidbody2D.velocity.y);
anim.SetFloat("Speed",Mathf.Abs(move));
facingRight = true;
}
// Are we touching the jump button?
if (UP.HitTest(t.position, Camera.main))
{
anim.SetBool("Ground",false);
anim.SetTrigger("Jumping");
rigidbody2D.AddForce(new Vector2(0,JumpForce));
}
if (DOWN.HitTest(t.position, Camera.main))
{
anim.SetBool("Crouching",true);
}
else anim.SetBool("Crouching",false);
}
// Did the touch end?
if (t.phase == TouchPhase.Ended)
{
// Stop all movement
rigidbody2D.velocity = Vector2.zero;
}