- Home /
Is it bad to add a mouse Lock at MouseLook Script?
I added an if condition in the MouseLook script, and I don't see any significant difference at the moment. I have the default FPController, a main and far camera. When I activate an onGUI trigger I add MouseLook.mouseLock = true and deactivate all cameras. Is that really wrong ? Should I do it in any other way ?
public float minimumY = -60F; public float maximumY = 60F;
public static bool mouseLock = false;
//so i can access the variable from everywhere.
float rotationX = 0F; float rotationY = 0F;
Quaternion originalRotation;
void Update (){
if (mouseLock==false)
//it all happens at the update...??!
{ if (axes == RotationAxes.MouseXAndY) { // Read the mouse input axis rotationX += Input.GetAxis("Mouse X") * sensitivityX; rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
rotationX = ClampAngle (rotationX, minimumX, maximumX);
.... etc
and here is how i call it ..
function OnTriggerEnter (hit:Collider) {
if((hit.gameObject.tag == "LiftGui") && (showMenu== false)) { MouseLook.mouseLock=true; showMenu = true; }
}
Answer by qJake · Mar 29, 2010 at 05:59 PM
So... your question is if your code is "wrong" or not? Because there's no right or wrong way to program something, I mean, sure, there are standards and practices and that sort of thing, but if your code works and shows no visible performance issue because of the code, I wouldn't say that it's "wrong"?
Short answer: If it works and doesn't make your game lag, it's fine.
Thanks SpikeX, I added a boolean in the update function of mouseLook to enable and disable camera rotation when I have GUIs. I just wandered if checking all the time if it is enabled is the right way. I don't have loads of models and scripts yet in the game to check if that is an issue. I hope you are right, I will wait for a bit and tick your answer.
Yes, you can check booleans during Update() just fine... that code runs so fast and takes so little time, it's probably nearly immeasurable. If you knew how many calculations and conditional statements are run every Update() on a major production game, you'd laugh at this question. ;)