I'm trying to make a simple flowing pipe-style rotation puzzle, but having issues getting Unity to properly recognize certain angles of rotation. My rotation script for the pieces:
private void OnMouseDown()
{
if (!GameControl.winState)
transform.Rotate(0f, 0f, 90f);
}
If the value of the z rotation is set to 90 or -90, the game works fine. However, if I try a different value such as 60 or 30 (and have corresponding 60 or 30 shifts to the puzzle hexes' z rotations to scramble the puzzle), the game fails to note a win state. Here is the game control script:
public Transform[] hex;
public GameObject successLight;
public static bool winState;
void Start () {
successLight.SetActive(false);
winState = false;
}
void Update ()
{
if (hex[0].rotation.z == 0
&& hex[1].rotation.z == 0
&& hex[2].rotation.z == 0
&& hex[3].rotation.z == 0
&& hex[4].rotation.z == 0)
{
Debug.Log("PuzzleSolved!");
winState = true;
successLight.SetActive(true);
}
}
I've also tried making the rotation using Euler angles, but still experienced the same problem. Is this an issue with the rotation not being exact and therefore unable to meet the conditions? Checking the inspector as the game runs, it looks as if even when the hexes all get to the proper z rotation of 0, the win state still isn't triggering when the rotation moves at a degree other than 90. Any help would be appreciated, feeling very confused at the moment.