- Home /
if(transform.Rotate) Doesn't Work?
I'm trying to check what angle my object is at and performing a particular task when it reaches that angle.
if(transform.Rotate.x > 85){
do something
}
But this does not work. What is the correct way to do this?
Thanks
Answer by Chris D · Aug 04, 2011 at 05:50 PM
transform.Rotate returns void and has no property x
.
Use transform.eulerAngles instead.
Answer by Laksh · Aug 04, 2011 at 06:58 PM
Hi
You should use :
transform.localRotation instead of transform.Rotate .
Regards
Laksh
Answer by DavidDebnar · Aug 04, 2011 at 07:39 PM
if(transform.localEulerAngles.x > 85) { doSomeStuff(); }
--David
Answer by filler03 · Aug 04, 2011 at 06:44 PM
Try transform.rotation.x
That wouldn't help much. Transform.rotation is a Quaternion. x,y,z,w of a quaternion are in range -1.0 to 1.0 and represent some kind of 4-dimentional complex number. You don't want to access the members of a quaternion directly. The Quaternion class in Unity have a special property(eulerAngles) that converts the quaternion into euler angles. The local euler angles are the numbers you see in the inspector.
The Transform class also have direct access to the eulerAngles in local and global space
transform.eulerAngles // same as transform.rotation.eulerAngles
transform.localEulerAngles // same as transform.localRotation.eulerAngles