Mathf.Clamp always equals 9

Mathf.Clamp takes arguments _rotationX, minimumVert, maximumVert. Why is the value always 9? Is it supposed to do this? Here is my code:

using UnityEngine;
using System.Collections;
using System.IO;
using System;
using System.Globalization;

public class MouseLook : MonoBehaviour {

public enum RotationAxes{
MouseXAndY = 0,
MouseX = 1,
MouseY=2
}
public RotationAxes axes = RotationAxes.MouseXAndY;
public float sensitivityHor = 9.0f;
public float sensitivityVert = 9.0f;

public float minimumVert = -45.0f;
public float maximumVert = 45.0f;

private float _rotationX = 0;

private StreamWriter sw;

void Start(){
sw = new StreamWriter(File.Open(“/Users/amc/Documents/WriteLines.txt”, FileMode.Create,
FileAccess.ReadWrite, FileShare.Read));
}
void Destroy(){
sw.Close ();
}
void Update(){
float mouse_y = Input.GetAxis (“Mouse Y”);
float mouse_x = Input.GetAxis (“Mouse X”);
if (axes == RotationAxes.MouseX) {
transform.Rotate (0, Input.GetAxis(“Mouse X”)*sensitivityHor, 0);

} else if (axes == RotationAxes.MouseY) {
sw.WriteLine("Before— mouse_y " + mouse_y + " " + “mouse_x " + mouse_x);
_rotationX -= Input.GetAxis (“Mouse Y”) * sensitivityVert;
//_rotationX = Mathf.Clamp(_rotationX,minimumVert,maximumVert);
//sw.WriteLine(”_rotationX: " + _rotationX);
//sw.WriteLine("minimumVert: " + minimumVert);
//sw.WriteLine("maximumVert: " + maximumVert);
Debug.Log(("Mathf.Clamp: " + Mathf.Clamp(_rotationX,minimumVert,maximumVert)));
sw.WriteLine("Mathf.Clamp: " + Mathf.Clamp(_rotationX,minimumVert,maximumVert));
//sw.WriteLine("Mathf.Clamp: " + Mathf.Clamp(0,0,0));

//sw.WriteLine("AFTER—_rotationX: " + _rotationX);
//sw.WriteLine("AFTER—minimumVert: " + minimumVert);
//sw.WriteLine("AFTER—maximumVert: " + maximumVert);

float rotationY = transform.localEulerAngles.y;
transform.localEulerAngles = new Vector3 (_rotationX, rotationY, 0);
sw.WriteLine("After— mouse_y " + mouse_y + " " + "mouse_x " + mouse_x);
} else {
}
}
}

No matter what values i insert for _rotationX, minimumVert and maximumVert it’s always 9

Use code tags, it makes it much easier to read your code

Please user the tags when posting your scripts.

Mathf.Clamp just resticts a value between two floats so it is _rotationX which equals 9

_rotationX -= Input.GetAxis ("Mouse Y") * sensitivityVert;

The -= operator subtracts from the target value. You probably want regular = here? Dunno, can’t really tell whats going on without code tags.

Aside from code tags being needed to help make your code more readable, I’m also wondering what it is you’re trying to do.

Clamp will return the value of rotationX unless it’s either below the minimum value or above the maximum value. So if it’s 9, you will always get 9.

The value of _rotationX is 0, but Mathf.Clamp is 9

I think I found out what the problem is. MinimumVert and MaximumVert both equal 9. Why I don’t know.