Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Ian-McCleary · Aug 26, 2014 at 07:22 AM · javascriptcharactercontrollerdisablemouselook

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

  
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

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.

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Ian-McCleary · Aug 26, 2014 at 08:00 AM 0
Share

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;
     }
 }
avatar image Ian-McCleary · Aug 26, 2014 at 08:01 AM 0
Share

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.

avatar image Tonyx97 · Aug 26, 2014 at 09:01 AM 0
Share

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.

avatar image Ian-McCleary · Aug 27, 2014 at 11:51 PM 0
Share

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

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

23 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges