fixing rotation on a specific axis

I found this script on a forum for almost what i was looking for:

var X_RotationLockedAt : int ; //locking the rotation at a certain angle for X
var Y_RotationLockedAt : int ; //locking the rotation at a certain angle for Y
var Z_RotationLockedAt : int ; //locking the rotation at a certain angle for Z

function FixedUpdate(){
     transform.rotation = Quaternion.Euler(X_RotationLockedAt, Y_RotationLockedAt, Z_RotationLockedAt);
}

But how do i get it to only freeze on one axis for example freeze on the Y axis but move with the parent object on X and Z, i tried

 transform.rotation = Quaternion.Euler.Y = Y_RotationLockedAt;

But it didn’t work… no errors just didn’t work!

Thanks in advance!

Try using this

transform.eulerAngles = Vector3(0, Y_RotationLockedAt, 0); //check : Y_RotationLockedAt is in Euler

I used for C#

transform.eulerAngles = new Vector3(0f,Y_RotationLockedAt,0f);