- Home /
Player Movement for Mobile
Hi There,
I am new here, in my code, everything is working great for Input.GetAxis("Horizontal"); but I can't move it for my mobile device. Please check my code below
public class PlayerControl : MonoBehaviour {
public bool canMove;
public static float moveSpeed = 25f;
[SerializeField]
float maxPos;
void Update()
{
if (!canMove)
{
Move();
}
}
private void Move()
{
float inputX = Input.GetAxis("Horizontal");
transform.position += Vector3.right * inputX * moveSpeed * Time.deltaTime;
float xPos = Mathf.Clamp(transform.position.x, -maxPos, maxPos);
transform.position = new Vector3(xPos, transform.position.y, transform.position.z);
}
}
I tried to make it working with UI Button but no luck. It's working with key press.
Hello.
I never did a project for mobile, but you should look for, at unity manuals or tutorials how to detect inputs with mobile.
Bye!
Your answer
Follow this Question
Related Questions
how can i move a ball like in rolling sky game using mobile touch and reach the same physics ? 0 Answers
Mobile Character controller Moving in world space 1 Answer
Mobile player controller assistance 1 Answer
Why isn't my joystick code working? 1 Answer
Joystick pack from unity assets not following the finger movement 1 Answer