coder008 coder008 - 2 months ago 15
C# Question

Axes cordinate mouseMove

im reading the book


Unity in action


and i have some problems trying to understand the meaning of a part of the code,
the object here is a player and he should with the mouse input see the envoirment, my doubt is just with the comparision, i dont get it why he compare values, he doesnt explain it very well, why i need to compare values, when i should see all, atleast horizontal, and i dont know very well, what he is comparing if someone can explain it to me i apreciate soo much.

here is the code:

using UnityEngine;
using System.Collections;

public class MouseLook : MonoBehaviour {
public enum RotationAxes {
MouseXAndY = 0,
MouseX = 1,
MouseY = 2
}

public RotationAxes axes = RotationAxes.MouseXAndY;

void Update() {
if (axes == RotationAxes.MouseX) {
// horizontal rotation here
}
else if (axes == RotationAxes.MouseY) {
// vertical rotation here
}
else {
// both horizontal and vertical rotation here
}
}
}


Ps: i dont put the code inside the conditions because that is not my main issue and the question has just to do with the comparision

Answer

enum RotationAxes allows you to select one value at a time from inspector window. And then rotation will be applied based on what you selected. There are three available options:

enter image description here

If you choose MouseX you will be able to look around horizontal axis only, similarly if you choose MouseY you can only look around vertical axis i-e up and down. If you want to look in both directions you will choose MouseXAndY from inspector.

Hope this helps