Hi everyone!
I’m having an issue that I can’t seem to solve on my own.
So, task is:
-
Have 4 2D objects with rotation at 0, 90, 180 and 270 placed on scene;
-
Clicking on them calls Rotation:
transform.Rotate(0f, 0f, 90f);
of element you’ve clicked on.
- Update checks if all objects are at 0 rotation:
if (
Mathf.Approximately(pictures[0].rotation.z, 0f) &&
Mathf.Approximately(pictures[1].rotation.z, 0f) &&
Mathf.Approximately(pictures[2].rotation.z, 0f) &&
Mathf.Approximately(pictures[3].rotation.z, 0f))
/*
pictures[0].rotation.z == 0 &&
pictures[1].rotation.z == 0 &&
pictures[2].rotation.z == 0 &&
pictures[3].rotation.z == 0)*/
{
winText.SetActive(true);
youWin = true;
}
Commented section seemed to work too, but switched due to advise from colleague.
All goes well, condition is met once all objects are at 0 degrees on Z axis.
!Problem occurs here!
- I’m trying to somplify level construction, so I try and reshuffle all pieces with code:
for (int i = 0; i < pictures.Length; i++)
{
float temp = Random.Range(0, 4);
pictures[i].Rotate(0f, 0f, 90f * temp);
}
And, for some reason, Update if-statement doesn’t recognise 0 value of all items.