- Home /
Multiple conditions
Hello guys , i wanted to ask you if i made a mistake in this code ,because "isAlligned" always stays false.I putted it in a function which is called on Update().
if((spinningPartObj.transform.rotation.z >= 88 && spinningPartObj.transform.rotation.z <= 92) || (spinningPartObj.transform.rotation.z >= 178 && spinningPartObj.transform.rotation.z <= 182) || (spinningPartObj.transform.rotation.z >= 268 && spinningPartObj.transform.rotation.z <= 272) || (spinningPartObj.transform.rotation.z >= 358 && spinningPartObj.transform.rotation.z <= 2)) { Debug.Log("Is alligned!"); isAlligned = true; } else { Debug.Log("Is not alligned!"); isAlligned = false; }
Answer by tanoshimi · Jul 10, 2015 at 03:32 PM
Yes. Your mistake is in thinking that transform.rotation.z
represents a rotation about the z axis, measured in degrees. It doesn't. transform.rotation.z is the third element of a quaternion. I suggest you look up eulerAngles: http://docs.unity3d.com/ScriptReference/Transform-eulerAngles.html
Answer by Dziugauskis · Jul 11, 2015 at 05:59 PM
Thank you for your response , i fixed it.Now i faced another problem.One UI image is rotating to Vector3.back
and another UI Image is rotating to Vector3.forward
, and i want to check when theirs rotation is the same but of course one element should be as Quaternion.Inverse
, but i just dont know how to use it. This line : if(spinningPartObj.transform.eulerAngles.z == Quaternion.Inverse(spinningPartBackObj.transform.eulerAngles.z))
gives me error , any other ways to check inversed rotation?
Please don't post additional questions as answers - this is not a threaded forum, it's a Q&A site. If your original question has been answered, please mark it as such. If you need to provide additional information, please use a comment or edit your original question. If you have a new question, please start a new question.
Your answer
Follow this Question
Related Questions
Spawning Statement Help 0 Answers
Quaternion.Inverse for UI.Image rotation 0 Answers
Why is door opening so fast with boolean condition? 0 Answers
Camera rotation 0 Answers
Delay something until no object has a certain condition 2 Answers