Variable Mathf.Clamp not working... (SOLVED)

Hello, what i’m trying to do is clamp a variable between: ‘277.2847’ and ‘-29.09483’

my code is:

var clampvar = 5f;
function Update () {
		Mathf.Clamp (clampvar,-29.09483,277.2847);
		Debug.Log(clampvar);
		clampvar += 50;
}

Thank you sooo much if you can tell me why this isn’t working :smiley:

You are not storing the clamped value, you are telling it, hey what is the clamped version of this, fine, nevermind just wanted to know. You need to store it somewhere, or overwrite the original value like this:

var clampvar : float = 5.0;

function Awake ()
{
       Debug.Log("Original value: " + clampvar);
       clampvar = Mathf.Clamp(clampvar, -29.09483, 277.2847);
       Debug.Log("Clamped value: " + clampvar);
       clampvar += 50;
       Debug.Log("Adjusted value: " + clampvar);

}