if clause trouble

The situation:

zAngle is a float.
minZ and maxZ are floats.

zAngle stays between 0 and 180.

The problem:

If I don’t use “if” below, shoulder spins around 360 degrees. I want to limit the rotation between two angles.

When the if statement is applied, the shoulder won’t rotate at all. Why not?

	if(zAngle>=minZ && zAngle<=maxZ){
	shoulder.transform.localEulerAngles.z = zAngle+270;
	}

Vector3 is a struct and so in C# when you modify the value like that it is updating a copy which is immediately discarded. You need to set the whole of localEulerAngles and not just a component of it.

Make sure minZ and maxZ have sensible values and add a Debug.Log to the body of the if statement to ensure that you are actually using a valid angle.