I do not know anything about C #, but I'm trying to develop a simple project on Unity. It consists of moving a crane. I did the code to move the bridge, but if I keep holding the button it keeps moving beyond the limit.
How can I limit the movement between two points, in this case, of the X axis since it only moves in it.
Here is the code:
public class MoveBarra : MonoBehaviour {
public float VelocidadeMov;
void Start () {
VelocidadeMov = .25f;
}
void Update() {
if(Input.GetKey(KeyCode.W))
{
transform.Translate(-VelocidadeMov, 0, 0);
}
if (Input.GetKey(KeyCode.S))
{
transform.Translate(VelocidadeMov, 0, 0);
}
}
}