Hi, so I’m studying the default MouseLook script and while I’ve made progress I do need to know how the ‘compiler’(or something) cycles through the code.
So, at the start we create an enumeration and then we set an instance of it equal to one of that enum’s members:
public enum RotationAxes { MouseXAndY = 0, MouseX = 1, MouseY = 2 }
public RotationAxes axes = RotationAxes.MouseXAndY;
So, for the rest of the script axes’ value is never changed. Which should surely mean that it will always == RotationAxis.MouseXAndY.
As shown in the code snippet which pretty much directly follows within Update():
if (axes == RotationAxes.MouseXAndY)
So the ‘compiler’ executes the code here because it must be true. Yet, later on we get other if and else statements claiming ‘axes’ to equal other values not obviously assigned to it.
Here is what I mean:
else if (axes == RotationAxes.MouseX)
axes should still equal RotationAxes.MouseXAndY, shouldn’t it? Then this code would never be executed, but clearly it must be executed or it wouldn’t be there.
So how does this work. ‘axes’ can seemingly equal MouseXAndY and then MouseX, I get that it’s a variable and so its value is subject to change but surely that change should be stated in the form of:
axes = something.
Yet the only time such an initialization occurs is at the start when it’s set equal to ‘MouseXAndY’.
Perhaps I’ve misunderstood how enums work.
If you can help that would be greatly appreciated and please let me know if I’ve been unclear.