I have a problem since I am new to unity, what I want is that when the object reaches a certain position on the x axis it stops, for example when it reaches 2 or -2 it stops at that point. In the code that I propose when it reaches that position, it stops and no longer moves in the opposite direction. Greetings.
// Update is called once per frame
void Update () {
float temp = Input.acceleration.x;
Mover (temp);
}
public void Mover(float temp){
float posicion = 2.0f;
if (transform.position.x > -posicion && transform.position.x < posicion) {
transform.Translate (temp * velocidadPosicion * Time.deltaTime, 0, 0, Space.World);
}
}