I have a plane witch i want to rotate in two ways:
var stato : int;
function Start () {
stato=1;
}
function Update () {
if(stato==1){
if(transform.rotation.z >= 10)
stato=0;
else
transform.Rotate (0, 0, 5 * Time.deltaTime );
}
it is not rotate in the second way…
I suppose, transform.rotation.z is never 10.
Are you sure? Unity reads rotation in quaternoins, meaning, they do not work on human principles. I would put a print in to double check the value returned, also, eulerAngles might work better.
can you write code to print, please?
function Update () {
print (transform.eulerAngles.z);
if(stato==1){
if(transform.rotation.z == 10.00585)
stato=0;
else
transform.Rotate (0, 0, 5 * Time.deltaTime );
}
Rotation change…but the If condition doesn’t chang var stato
print("transform.rotation.z " + transform.rotation,z);
See what that prints as it is that you are checking.
Please use code tags when posting code. Transform.rotation is a 4D quaternion, which is not euler angles, and rotation.z is not the z axis. Don’t attempt to read or modify individual elements of quaternions unless you understand them. Also don’t check floats with == because that condition will pretty much never be true.
–Eric
Thank you!!! I have done!