Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by Marks98 · May 25, 2017 at 07:12 PM · c#script.change

How can i change variables in FirstPersonController scripts?

Hi. I creating pause menu in my game. When player click on whatever button in menu, cursor become hide. I have idea, how can i block cursor hide, but variables not changed. I use to help this site : http://answers.unity3d.com/questions/988322/how-can-i-access-firstpersoncontroller-script-vari.html

In my code have this: link to file:

 public UnityStandardAssets.Characters.FirstPerson.MouseLook controller;

And changing variable when player press esc

 controller.menuLocker = true;

Then in player controller i declared variable type bool and set it default as false. Like here:

 public bool menuLocker = false;

My problem is, when i press esc and menu show me, variable is not switched. What i do wrong? Where i have problem? Thanks to all, who help me.

Comment
Add comment · Show 1
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 Marks98 · Jun 17, 2017 at 07:10 PM 0
Share

I created it in different way. I disabled lock cursor in mouseLook and create own. It working nicely.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by PizzaPie · May 25, 2017 at 09:32 PM

Interesting, does that even get compiled? First of all controller is of MouseLook type so if you declared the menuLocker inside the FirstPersonController(gonna call it FPSc from now on) controller.menuLocker = true; should through a compiler error. Any way to get a reference(link) to the active instance of the FPSc you need to do something like this :

 using UnityStandardAssets.Characters.FirstPerson;    //this is to avoid long names
 public class MyClass : MonoBehaviour {
 //...
 
 public FirstPersonController controller;  
 private MouseLook mLook;        //this is if you need a reference to the MouseLook instance the FPSc is using
 
 void Awake(){
        mLook = controller.m_MouseLook;       //this sets the reference
 }
 void Start(){
        controller.menuLocker = true;        //this will access the menuLocker field in the active FPSc
 }}

of course you need to put it on an GameObject inside the scene and then drag and drop the GameObject that contains the FPSc on the field controller. Also you need to go to the FPSc script find the m_MouseLook field and change it to public.

Note: the easiest way to stop this Cursor behaviour is to just disable the FPSc component you have active in scene while you are on menu and re enable it afterwards.

Note2: keep in mind that Unity in edit mode( inside editor) have a safenet that causes the cursor to get unlocked with esc regardless of your scripts, which might cause some funky behaviours some times. Doesn't happen on builds.

Note3: watch out for the UpdateCursorLock() inside MouseLook class because it is the culprit that relocks the cursor on click and it is called internally inside LateUpdate on MouseLook and somewhere inside the FPSc script, quite annoying approach if you ask me.

Comment
Add comment · Show 2 · 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 Marks98 · May 26, 2017 at 06:26 PM 0
Share

I don't understand you very much. I try your code and nothing. Became some errors, thats all. I try too set value via method inside $$anonymous$$ouse Locker, but still not working. I don't know why.

 public void Change$$anonymous$$enuLocker(bool state){
             menuLocker = state;
             Debug.Log ("Provedlo se");
 }

 controller.Change$$anonymous$$enuLocker (false); // in menu script

Thaks

avatar image PizzaPie Marks98 · May 29, 2017 at 06:05 PM 0
Share

How do you set the reference to the controller? $$anonymous$$anually through Editor or on Runtime or you use new keyword? Is the menuLocker located inside $$anonymous$$ouseLook or inside FirstPersonContoller class? Please post your class that tries to manipulate the others. Cheers.

avatar image
0

Answer by Marks98 · May 30, 2017 at 04:44 PM

I set reference to MouseLook manually, and yes, the Mouse Look is inside prefab first player controller. public UnityStandardAssets.Characters.FirstPerson.MouseLook controller; // reference to file

 public void GameMenuBackGame(){ //if player click on the button
         gameMenu.enabled = false;
         controller.ChangeMenuLocker (true);
     }
 
     // Update is called once per frame
     void Update () {
         if (Input.GetKeyDown(KeyCode.Escape)) {
             if (gameMenu.enabled == false) {
                 gameMenu.enabled = true;
                 controller.ChangeMenuLocker (false);
             }
         }
     }

This is all code, where i trying manipuled with variable. Thanks

Comment
Add comment · Show 2 · 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 PizzaPie · May 30, 2017 at 05:33 PM 0
Share

You sure you drag and drop the Object with the $$anonymous$$ouseLook from your hierarchy and not the Assets? But i am quite sure there is no $$anonymous$$ouseLook Component on the FirstPersonController prefab, maybe they changed it on the last Update.

avatar image Marks98 PizzaPie · Jun 01, 2017 at 08:36 PM 0
Share

I don't know where is problem. $$anonymous$$abye is better for me write own mouse look script.

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

360 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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

How can i move object between two positions ? 1 Answer

Use c# "ref" with a GameObject or Component 1 Answer

How Create a menu in script and inspector ?? 2 Answers

Camera is Moving in Inspector but not in game? 1 Answer

Destroying enemy only partially works 0 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