- Home /
enum variables change only one time
Hi. I'm working on 2,5D game, 2D sprites in ortographic 3D enviroment with XCOM-like camera (fixed angle of view and Q-E rotation with step of 90 degrees). Trying to create some sort of global coordinate system to properly switch side of sprites, but stuck with one trouble: in play mode, enum values for directions (north, east, south, west) changes only one time (tested with Debug.Log). Every value leaves its debug text only one time, and don't react after that. But I need to change them constantly when I rotate a camera for translate prore value of observation side for sprites. Script attached to main camera focus point (blank object on the ground level). Here is my code:
public class DirectionsScript : MonoBehaviour
{
public enum Direction {North, East, South, West};
Direction currentDir;
void Update()
{
currentDir = Direction.North;
if (transform.rotation.eulerAngles.y > 359 & transform.rotation.eulerAngles.y < 1)
{
currentDir = Direction.North;
Debug.Log ("North");
}
if (transform.rotation.eulerAngles.y > 89 & transform.rotation.eulerAngles.y < 91)
{
currentDir = Direction.East;
Debug.Log ("East");
}
if (transform.rotation.eulerAngles.y > 179 & transform.rotation.eulerAngles.y < 181)
{
currentDir = Direction.South;
Debug.Log ("South");
}
if (transform.rotation.eulerAngles.y > 269 & transform.rotation.eulerAngles.y < 271)
{
currentDir = Direction.West;
Debug.Log ("West");
}
}
}
Sorry for broken english, it's not my native language. Thanks for advance.
Answer by Bunny83 · May 10, 2019 at 12:54 AM
You probably have enabled collapse in your console window. Deactivate it. However if collapse is enables there should be a counter on the right of each message telling you how many have occurred already. If you need to know the exact order of the individual messages you have to disable collapse.
Note that your title is misleading as your issue is not related to the enum at all. You check the eulerangles and based on that you print a hardcoded debug text. If you take out the whole enum stuff nothing will change in regard to the printed text in the console.
Also note that using euler angles can cause issues since euler angles do not have a unique representation of a certain orientation. The next issue is you narrowed your "active areas" down to a 2° window for each direction. This is a quite narrow range. If you control the rotation with the mouse you can easily skip over that range and of course the direction won't update in this case.
Thanks, dude, that's really be a collapse button. When I turn it off - all start to works as I thought. ... Camera moves with Q and E press, for fixed steps and angle 90 degrees. Not by mouse. Even with a fixed value in code it works correctly.