Input.GetAxis("Vertical") not working on Mobile Phone
Hi,
I'm a newbie in Unity Game Development. I'm currently working on a very basic 2D game. The following code works on my PC using arrow keys:
float yPos = gameObject.transform.position.y + (Input.GetAxis("Vertical") * playerSpeed);
playerPos = new Vector3(-23, Mathf.Clamp(yPos, -11, 11), 0);
gameObject.transform.position = playerPos;
But when I'm trying to test this game in my mobile phone, it's not working. How can I get the swipe up and swipe down touch input?
Answer by ssnigdho · May 04, 2016 at 08:44 PM
One fantastic thing about Unity forum is no one replies, ever!!
However, I've figured this out. For other newbies, here's the code:
float playerSpeed = 0.1F;
float yPos = gameObject.transform.position.y + (Input.GetTouch(0).deltaPosition.y * playerSpeed);
playerPos = new Vector3(-23, Mathf.Clamp(yPos, -12.6F, 12.6F), 0);
gameObject.transform.position = playerPos;
Thanks for putting it here, I was crazy looking for it.
Your answer
Follow this Question
Related Questions
Making object follow finger? 1 Answer
Touch does not work with the new Input System 5 Answers
Unity 2d android game How to "freeze" position on Y axis 1 Answer
useDragThreshold is set to false, but the threshold is still there... 1 Answer
Simple cell-based game goes bonkers when clicked on the edge of the cell 0 Answers