- Home /
turn mouse look on and off using the 'm' key
I have a crate that opens when you press 'e' and a loot window appears thats when i want to disable my FpsMouseLook then when im done picking my item and close the loot window i can turn the FpsMouseLook back on using the same button to turn it off 'm' I can turn it off but cant get the mouselook to turn back on. here what i got please help
public enum RotationAxis {MouseX = 0, MouseY = 1}
var RotationAxisRotationXY = RotationAxis.MouseX || RotationAxis.MouseY;
var sensitivityX : float = 400f;
var minimumX : float = -360f;
var maximumX : float = 360f;
var RotationX : float = 0f;
var OriginalRotation : Quaternion;
var RotationY : float = 0f;
var minimumY : float = -25f;
var maximumY : float = 25f;
var sensitivityY : float = 400f;
function Update () {
//******************Here is where im trying to turn it on and off***********//
if(Input.GetButton ("Fire1") && GetComponent (FpsMouseLook))
Destroy (GetComponent (FpsMouseLook));
//*************************************************************************//
if(RotationAxisRotationXY == RotationAxis.MouseX){
RotationX += Input.GetAxis ("Mouse X") * sensitivityX * Time.deltaTime;
RotationX = ClampAngle (RotationX, minimumX, maximumX);
OriginalRotation = XQuaternion = Quaternion.AngleAxis (RotationX , Vector3.up);
transform.localRotation = OriginalRotation * XQuaternion;
}
if(RotationAxisRotationXY == RotationAxis.MouseY){
RotationY -= Input.GetAxis ("Mouse Y") * sensitivityY * Time.deltaTime;
RotationY = ClampAngle (RotationY, minimumY, maximumY);
OriginalRotation = YQuaternion = Quaternion.AngleAxis (RotationY, Vector3.right);
transform.localRotation = OriginalRotation * YQuaternion;
}
}
static function ClampAngle (Angle, min, max): float {
if(Angle < -360){
Angle += 360;
}
if(Angle > 360){
Angle -= 360;
}
return Mathf.Clamp (Angle, min,max);
}
It probably doesn't help that you're actually destroying the mouselook component, ins$$anonymous$$d of setting
GetComponent(Fps$$anonymous$$ouseLook).enabled = aBooleanWhichSetsWhetherItsOn;
Well I tried this and it still does the same thing it turns off but wont turn back on.
if(Input.GetButton ("Fire1") && GetComponent (Fps$$anonymous$$ouseLook)) GetComponent("Fps$$anonymous$$ouseLook").enabled = false; else GetComponent("Fps$$anonymous$$ouseLook").enabled = true;
Is this all happening inside said Fps$$anonymous$$ouseLook? Because that would explain why it isn't working.
Answer by Proportion · Oct 16, 2011 at 06:16 AM
lol yea if that script is fpsmouselook, if you destroy it you cant use that script to turn in on. instead just wrap what u want to turn on and off in a big if.
if(getkey("m")
haveIPressedMBoolean = true
if(haveIPressedMBoolean)){
//all your fps script
}
What syclamoth was saying is, if you disable the script that checks for the input then it won't check for the input that turns it back on.
One way to solve this is to have an external script check for user input and set the bool from outside.
Another way is to break your mouse look Update into two different functions, one for the FPS mouse look and one for the other and use an if check in Update to deter$$anonymous$$e which one to call. i.e:
function Update()
{
FPSbool = Input.Get$$anonymous$$eyDown("m");
if (FPSbool)
FPS$$anonymous$$ouseLook();
else
Other$$anonymous$$ouseLook();
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Help In Making a SphereCast for 3D Tire! Working RayCast Script included! 0 Answers
Pause Menu Wont Disable Mouse,Pause menu wont disable Player Controls 0 Answers
How to keep my cursor inside window boundaries 0 Answers
Baffling Input.Mouseposition problem. If statement not correctly working. 1 Answer