- Home /
Question by
Vlad bruma · Jan 13, 2015 at 06:58 PM ·
android2drotationrotate2d rotation
how to rotate 2d obj on android
So i have this code which is supposed to rotate a 2d object 90 degrees on android....and the problem is that it does that but only on pc...not on android. When i run the game on android and i press the left side of the screen it rotates once and then it will not work anymore. Can somebody help me? Thanks!
void Update ()
{
if (Input.GetMouseButton(0))
{
if (Input.mousePosition.x < Screen.width/2)
{
transform.rotation = Quaternion.Euler(0,0,i * 90);
i++;
}
else if (Input.mousePosition.x > Screen.width/2)
{
jump = true;
}
}
}
Comment
Best Answer
Answer by Denvery · Jan 13, 2015 at 09:34 PM
Try to work with Touches instead of Mouse. I.e., use Input.touchCount and Input.GetTouches(0).position instead of Input.GetMouseButton(0) and Input.mousePosition respectively.
void Update ()
{
if (Input.touchCount > 0)
{
if (Input.GetTouches(0).position.x < Screen.width/2)
{
transform.rotation = Quaternion.Euler(0,0,i * 90);
i++;
}
else if (Input.GetTouches(0).position.x > Screen.width/2)
{
jump = true;
}
}
}