- Home /
Question by
William Cain · May 05, 2012 at 03:19 AM ·
cameramultiplayermenuboolean
Enable Camera movment on/off with one button
This is a slightly different situation than What I have been able to find. I want to press 'm' and open up a gui menu but disable camera movment in my multiplayer game. I am close but not quite there with it. I want to hit 'm' open the menu (which I have done) and hit 'm'again and close it. While the menu is open freeze the camera movements. Here is what I have:
var openMenu : boolean = false;
var mouseMove : boolean = true;
function Update () {
if (networkView.isMine){
if (mouseMove == false)
{
myCamera.GetComponent("MouseLook").enabled=false;
}
if (Input.GetKeyDown ("m"))
{
openMenu=!openMenu;
mouseMove = !mouseMove;
}
}
I am not sure how to enable and disable off of just one button. Thanks for the help guys!
Comment
Best Answer
Answer by hijinxbassist · May 05, 2012 at 06:49 AM
Try using get key up instead, since keyDown may cycle those booleans multiple times. With 'keyUp' you know it will only get called once.
if (Input.GetKeyUp("m"))
{
openMenu=!openMenu;
mouseMove = !mouseMove;
}
and then this part needs to enable the component as well
var mouseLook:MouseLook=myCamera.GetComponent(MouseLook);
if (mouseMove == false)
{
mouseLook.enabled=false;
}
else if(!mouseLook.enabled)
{
mouseLook.enabled=true;
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613071119im_/https://answers.unity.com/themes/thub/images/avi.jpg)