x


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;
    }


}
more ▼

asked Mar 29 '10 at 04:18 PM

alexnode gravatar image

alexnode
984 27 32 49

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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.

more ▼

answered Mar 29 '10 at 05:59 PM

qJake gravatar image

qJake
11.6k 43 78 161

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.

Mar 29 '10 at 07:17 PM alexnode

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. ;)

Mar 29 '10 at 07:51 PM qJake

LOL ! Apparently I don't ... thanks.

Mar 30 '10 at 08:40 AM alexnode
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2999
x984
x495
x162
x125

asked: Mar 29 '10 at 04:18 PM

Seen: 1713 times

Last Updated: Mar 29 '10 at 04:18 PM