–Scene
----GameObject1
----GameObject2
-------GameObject3(child of GameObject2)
Each of those game objects has some random rotation.
I need to rotate the GameObject2 in such way where global (not local) rotation of the GameObject3 is identical to the rotation of the GameObject1. (As in achieve state where: if(GameObject1.transform.rotation == GameObject3.transform.rotation) is true)
The local rotation of the GameObject3 cannot be changed in any way at all, all rotation changes are done to the GameObject2.
What you need to do is get the quaternion that represents the rotation from the child object (gameObject3) to your target object (gameObject1). Then you apply that rotation to gameObject2. That will look something like this:
Edit: I realized that this doesn’t account for gameObject2’s rotation. The above would only work if gameObject2’s rotation was zero (Quaternion.identity). But since we’re changing it’s rotation to whatever we need anyway, the simple fix is to just clear it before we do our calculations!