- Home /
Question by
todorv · Nov 12, 2017 at 02:20 PM ·
androidaccelerometer
Accelerometer movement limit according to screen size
Hello, I am using this code to limit the movement of my gameOjbect ( I dont want it going out of the screen ) And those hard coded values ( -6.9 and 6.9) work in the editor but the screen on my phone is larger and I want them to fit. I was told to use screen width and height but i dont know how if someone can give me link or something I would really appreciate it.
void Update()
{
accel = Input.acceleration.x;
transform.Translate (0, 0, accel);
transform.position = new Vector3 (Mathf.Clamp (transform.position.x,-6.9f, 6.9f), -4.96f, 18.3f);
}
Comment