Rounding

Is there a way to Round a Transform.position.x?
I want an AI to look at the player but snap to one of his 4 walls surrounding him

http://lmgtfy.com/?q=Unity+Round

Ive checked this out Before but that only rounds it to the closest (1) value , I want it to round to the closest 0,90,180,270 degree rotation

Well the noobiest way would to say

if(transform.x > 135  transform.x < 255) //so I got 135 by doing 90+180=270/2=135 -- 180+270=450/2=255
    transform.x = 180;

I’m sure there is some built in feature but that would be from complete and utter scratch. Just think to yourself where it would round from, midway between 0 - 90 there is a point at which you’r gonna switch. SO if you greater than that point then you gonna go to 90… and so on.

Thanks for showing this trick , i was thinking about something like this and im thinking its the best option at the moment
Thanks - Uta =)

var roundingDegree : int=90;

transform.position.x = Mathf.Round (transform.position.x/roundingDegree)*roundingDegree;