Problem with Constraint Camera Rotation C#

using UnityEngine;
using System.Collections;

public class ConstraintRotation : MonoBehaviour {
	public enum ConstraintAxis{X = 0, Y, Z};

	public ConstraintAxis axis; 			// Rotation around this axis is constrained
	public float min;						// Relative value in degrees
	public float max;						// Relative value in degrees
	private Transform thisTransform;
	private Vector3 rotateAround;
	private Quaternion minQuaternion;
	private Quaternion maxQuaternion;
	private float range;
	
	void Start()
	{
		thisTransform = transform;
		
		// Set the axis that we will rotate around
		switch ( axis )
		{
		case ConstraintAxis.X:
			rotateAround = Vector3.right;
			break;
			
		case ConstraintAxis.Y:
			rotateAround = Vector3.up;
			break;
			
		case ConstraintAxis.Z:
			rotateAround = Vector3.forward;
			break;
		}
		
		// Set the min and max rotations in quaternion space
		var axisRotation = Quaternion.AngleAxis( thisTransform.localRotation.eulerAngles[ axis ], rotateAround );
		minQuaternion = axisRotation * Quaternion( min, rotateAround );
		maxQuaternion = axisRotation * Quaternion.AngleAxis( max, rotateAround );
		range = max - min;
	}
	
	// We use LateUpdate to grab the rotation from the Transform after all Updates from
	// other scripts have occured
	void LateUpdate() 
	{
		// We use quaternions here, so we don't have to adjust for euler angle range [ 0, 360 ]
		var localRotation = thisTransform.localRotation;
		var axisRotation = Quaternion.AngleAxis( localRotation.eulerAngles[ axis ], rotateAround );
		var angleFromMin = Quaternion.Angle( axisRotation, minQuaternion );
		var angleFromMax = Quaternion.Angle( axisRotation, maxQuaternion );
		
		if ( angleFromMin <= range && angleFromMax <= range )
			return; // within range
		else
		{		
			// Let's keep the current rotations around other axes and only
			// correct the axis that has fallen out of range.
			var euler = localRotation.eulerAngles;			
			if ( angleFromMin > angleFromMax )
				euler[ axis ] = maxQuaternion.eulerAngles[ axis ];
			else
				euler[ axis ] = minQuaternion.eulerAngles[ axis ];
			
			thisTransform.localEulerAngles = euler;		
		}
	}
}

this is my code, and the Console is saying some errors

The best overloaded method match for `UnityEngine.Vector3.this[int]’ has some invalid arguments

Argument #1' cannot convert ConstraintRotation.ConstraintAxis’ expression to type `int’

The best overloaded method match for `UnityEngine.Quaternion.AngleAxis(float, UnityEngine.Vector3)’ has some invalid arguments

Can someone help me? It’s a script to Constraint X rotation of the main camera.

Just cast axis to an int everywhere you use it as an index in an array:

euler[ (int)axis ] = maxQuaternion.eulerAngles[ (int)axis ];

You also have a ‘.AngleAxis’ missing on line 37.

For this to work: public enum ConstraintAxis{X = 0, Y = 1, Z = 2};

The script works ok!

Robertbu already resolved it for me, but your answer is valid if I wanted to use y and z, I made this from a js script, this is why my code has problems, forgot to set INT. But thanks!