- Home /
How to Disable Mouse and Character movement? (Javascript)
Hi, i would like to be able to disable my mouse and character movement when they are in the pause menu screen. I saw an answer for this in C# but i am using javascript and im not knowing enough on how to write it in javascript. I tried using variables for MouseLook and a variable for a CharacterController but it didnt work mainly because i am unable to apply these settings in the inspector. This is because my game is multiplayer and the Character Controllers spawn in as players join.
I achieved disabling the all other character motors, mouselook, and maincameras in C# so that way the player renders only one at a time and so that not all players are controlled by one person pressing one button. (basically they were all controlled by any one person and moved together.) the script i used for that is below.
I am using the photon cloud to network and i start with all character motors, mouselook, and maincameras off. i then enable them for only that one character who spawned in. i believe thats the "myPlyaerGO". also the reason FPSWalkerEnhanced and MouseLook have MonoBehaviour is because those scripts are in javascript.
I just need for someone to tell me how to do this in java-script along with how to disable the character controller (i believe it controls the mouses Y axis so it needs to go as well) I think i should be disabling only that persons scripts and not the whole games so that not everyone freezes up (if thats possible in javascript)
The code is below and thanks in advance to anyone who can help me out! Sorry if this is confusing but i really need help so please ask questions. Thanks!
Here is the C# code i need in javascript along with disabling the character controller.
((MonoBehaviour)myPlayerGO.GetComponent("FPSWalkerEnhanced")).enabled = true;
((MonoBehaviour)myPlayerGO.GetComponent("MouseLook")).enabled = true;
myPlayerGO.transform.FindChild ("MainCamera").gameObject.SetActive(true);
myPlayerGO.transform.FindChild ("Inventory").gameObject.SetActive(true);
}
Answer by Tonyx97 · Aug 26, 2014 at 07:43 AM
You can create a function on C# Scripts (mouse look and character controller) for example:
public bool mEnabled = false;
void setMovingEnabled (bool state)
{
mEnabled = state;
}
so, what can you do with this?, you can put on mouse look for example a condition before execute the camera moving such as if (!mEnabled) return;
so if the moving is false the camera will not move, you can call this function from JS making GameObject.Find("thenameofgameobjectthatcontaisthemouselookscript").GetComponent ("MouseLook").setMovingEnabled (a boolean);
Do the same thing for character controller, for my project I only have done the mouse look disabling, but not character controller, I suppose that is easily as the mouse look.
ok, so for my function update (which i have in javascript because that what the pause menu is in) I need the script to be in javascript and i tried this but its not working. It says Assets/Script/Pause$$anonymous$$enu.js(36,55): BCE0049: Expression 'GameObject.Find('player').GetComponent('FPSWalkerEnhanced')' cannot be assigned to. here is what i put for the function update.
function Update ()
{
if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Escape))
{
Screen.lockCursor = true;
GUIEnabled = !GUIEnabled;
menu = !menu;
paused = !paused;
UpdateCursorLock();
GameObject.Find("player").GetComponent("FPSWalkerEnhanced") = false;
}
}
Please understand i also tried this with "$$anonymous$$ouseLook" and it didnt work either. im 100% that its the correct player and name of the script though.
GameObject.Find("player").GetComponent("FPSWalkerEnhanced") = false;
this is wrong, you have to call any function, not defining directly a boolean or any variable, so you have to create a function on FPSWalkedEnhanced to change the variable into the FPSWalkedEnhanced script. For example:
GameObject.Find("player").GetComponent("FPSWalkerEnhanced").disableFPSWalked(false);
you have to create disableFPSWalked function on FPSWalked script to change the variable.
I figured it out man, thanks for the help! Im glad you told me i was doing it wrong. it works almost perfectly now. $$anonymous$$y new problem if finding one of my cameras because i deleted the character motor. You answered my question though, thanks!
Your answer
Follow this Question
Related Questions
Unable to disable the MouseLook script 2 Answers
Disable all instances of a component 2 Answers
Script to disable MouseLook? 2 Answers
disabling a script (MouseLook) 5 Answers
Why doesn't this animation script work? 3 Answers