Answers for "Problem with rotation around axis"
http://answers.unity.com/questions/1176585/problem-with-rotation-around-axis.html
The latest answers for the question "Problem with rotation around axis"Answer by Eno-Khaon
http://answers.unity.com/answers/1176731/view.html
This seems like a needlessly complicated solution to a very simple problem.
What you're encountering is Unity's order of operations when converting [Quaternion][1] rotations to [Euler angles][2]. Specifically, they are processed by the Z rotation, followed by X, followed by Y.
Therefore, on your last pair of examples, rather than rotating by <b>90f</b> or <b>-90f</b>, followed by <b>(90f * GD.rot)</b>, you're instead doing it the opposite way. Then, if you move that to the Y-axis rotation instead, it's done in the opposite order. By coincidence, you wind up with the same rotation.
But, again, this seems like quite an overwhelming solution to a reasonably simple problem.
From the looks of it, you should be able to build this rotation like this instead:
g.rotation = Quaternion.AngleAxis(90f * GD.rot, Vector3.up);
In other words, rather than trying to set the local rotation to counteract the parent's(?) rotation, you could set the global rotation instead and cut out the middle man.
That said, if you're dead set on modifying the local rotation, you will instead need to break the rotation apart into two stages to make it foolproof. First, you can set the current local rotation to the [inverse][3] of the main rotation (i.e. your <b>90f</b> and <b>-90f</b>), then apply the secondary rotation of <b>(90f * GD.rot)</b>.
g.localRotation = Quaternion.Inverse(transform.rotation) * Quaternion.Euler(0, 90f * GD.rot, 0);
// or...
g.localRotation = Quaternion.Inverse(transform.rotation) * Quaternion.AngleAxis(90f * GD.rot, Vector3.up);
Either way, it can simplified into a single process rather than a 6-part, strictly cardinal-direction-based if statement.
Edit: For what it's worth, once you break the rotation process apart into multiple stages to avoid running into issues with the order of operations, you'll always wind up with the same results; one rotation to undo the parent's rotation will result in the following rotation being axis-aligned with global coordinates, so the second rotation would always be able to be the same.
[1]: http://docs.unity3d.com/ScriptReference/Quaternion.html
[2]: http://docs.unity3d.com/ScriptReference/Quaternion-eulerAngles.html
[3]: http://docs.unity3d.com/ScriptReference/Quaternion.Inverse.htmlMon, 25 Apr 2016 18:43:58 GMTEno-Khaon