My script is working almost perfectly, but I just need to clamp this float and I can't seem to figure out how.
A simplified version...
public HingeJoint doorHinge;
public float rotatedoor = 0.0f; // Limit this value, min 0 max 120
void Update () {
float h = Input.GetAxis("Mouse X");
rotatedoor = rotatedoor + h;
JointSpring doorSpring = Door.spring;
doorSpring.targetPosition = rotatedoor;
Door.spring = doorSpring;
}
I tried adding a min and max float value and then using
rotatedoor = Mathf.Clamp(rotatedoor, minRot, maxRot);
but no luck.
Any help is appreciated.