if (Target.rotation.y == 0.60)
{
Target.rotation = Quaternion.identity;
}
if (Target.rotation.y == -0.60)
{
Target.rotation = Quaternion.identity;
}
Currently I’m using this code for the rotation of my target but instead of resetting the rotation I want Just Stop it from rotating any further.
Any way I can do this ?, would be glad to receive any help.
You cannot compare floating point values for equality due to fixed point imprecision. You may compare it with Mathf.Approximately(), but if the values are moving fast enough, it will go right past your check.
ALSO, the .y component of a Quaternion is NOT the Euler angle. It has nothing whatsoever to do with angles. It is an internal component of the four floating point numbers inside a Quaternion.
If you want the angle, subject to gimbal lock if you go beyond 90 degrees, you can check the .eulerAngles.y property, but I do NOT recommend using this because of the gimbal lock problem.
For rotating only on one axis, keep your own separate float variable, adjust it accordingly, and use it to set the rotation explicitly, such as:
Target.rotation = Quaternion.Euler( 0, myYAngle, 0);