# CCTV Camera doesn't rotate?

My code:

``````def Start ():
moveright = false
rot = transform.eulerAngles.y

def Update ():
Debug.Log(rot)
Debug.Log(moveright)
cameray = transform.eulerAngles.y
if rot == 0:
if cameray > 45:
if cameray < 275:
moveright = true
if cameray < 315:
if cameray > 275:
moveright = false
if moveright == true:
transform.Rotate(Vector3(0,-maxrotationspeed*Time.deltaTime,0),Space.Self)
if moveright == false:
transform.Rotate(Vector3(0,maxrotationspeed*Time.deltaTime,0),Space.Self)

if rot ==  90:
if cameray > 135:
if cameray < 355:
moveright = true
if cameray < 45:
if cameray > 20:
moveright = false
if moveright == true:
transform.Rotate(Vector3(0,-maxrotationspeed*Time.deltaTime,0),Space.Self)
if moveright == false:
transform.Rotate(Vector3(0,maxrotationspeed*Time.deltaTime,0),Space.Self)

if rot == 180:
if cameray > 225:
moveright = true
if cameray < 135:
moveright = false
if moveright == true:
transform.Rotate(Vector3(0,-maxrotationspeed*Time.deltaTime,0),Space.Self)
if moveright == false:
transform.Rotate(Vector3(0,maxrotationspeed*Time.deltaTime,0),Space.Self)
``````

This code works while rot == 0, but does not work under any of the other conditions. Any idea why?

Rotation values are not exact. They are stored as floats which have limited precision. You may type `90` as the rotation, but internally it is `90.00001`. The slight discrepancy can be checked using `Mathf.Approximately` as in:

``````if Mathf.Approximately(rot, 90)
``````

Float values should never be compared using the `==` comparator. `0` works because it can be stored exact in a float.

Or better yet, use an animation like @Sericet suggests. Doing so will allow arbitrarily rotated cameras to work.