I m making a game on android device , i use accelerometer and i want my player to transform only on x axis.
this is the code i write:
void Update()
{
float amtToMove = -Input.acceleration.y * PlayerSpeed * Time.deltaTime;
Vector3 pos = transform.position;
pos.x = Mathf.Clamp(pos.x + amtToMove, -0.19f, 2.3f);
transform.position = pos;
}
I use Mathf.Clamp and this work very well but i don’t want to put a fixed value.
i want my player to be limited on screen width.
Can any one help me
PS: Sorry for my bad english and
thanks in advance.