Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
1
Question by d112570 · May 25, 2015 at 06:10 PM · pausedisablefirst-person-controller

Disable first person controller script, how?

I have tried this on Unity 5, but does not work.

 GameObject.Find("Player").GetComponent<FirstPersonController>.enabled = false;

I also tried

 GameObject.Find("Player").GetComponent<UnityStandardAssets.Characters.FirstPerson>.enabled = false;
 GameObject.Find("Player").GetComponent<CharacterController>.enabled = false;

None work.

Upon pausing the game with the script, the music and the movement pauses, but the mouse still looks around.

Comment
Add comment · Show 4
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 SterlingSoftworks · May 25, 2015 at 06:27 PM 0
Share
 GameObject.Find("Player").GetComponent<FirstPersonController>().enabled = false;

You forgot the () at the end of the GetComponent()

avatar image d112570 · May 25, 2015 at 06:58 PM 0
Share

GameObject.Find("Player").GetComponent().enabled = false;

Does not work in Unity 5, even if the scripts name is FirstPersonController. In unity 4 it would of worked. I can disable it manually, but not via script.

avatar image SterlingSoftworks · May 25, 2015 at 07:02 PM 0
Share

What if you just create a bool to disable the entire script?

 If(boolName == false){
 //do nothing
 }
 else {
 ...your code here
 }

Sorry about my earlier comment, I have not had the need to disable a script so I figured it would work the same and saw you were missing the ().

avatar image d112570 · May 25, 2015 at 07:06 PM 0
Share

I've already created the bool, I want first person script to enable when its true and disable when its false. It is for the pause menu, I don't want the mouse to be looking around. In unity 5 its soooo different. In Unity 4 I disable the mouseLook, there is no mouse look script in Unity 5 to disable.

4 Replies

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

Answer by ConanJables · May 26, 2015 at 06:35 AM

I just had success with your original idea

             FPSController.GetComponent<FirstPersonController>().enabled = false;
 

All I had to do was append the following at the top of my code. It allows you to access FirstPersonController

 using UnityStandardAssets.Characters.FirstPerson;


I hope this helps

-ConanJables

Comment
Add comment · Show 5 · 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 d112570 · May 26, 2015 at 11:31 AM 0
Share

hmm, my comment disappeared, where did it go, I'll just rewrite my comment!!!

I used this at the beginning

 using UnityStandardAssets.Characters.FirstPerson;

and inside an if statement I used this.

 GameObject.Find("Player").GetComponent<FirstPersonController>().enabled = false;

Now the game pauses correctly. thx, a lot of people had questions and none had answers.

avatar image jordanneff · Aug 09, 2015 at 07:59 AM 0
Share

Hey could you post your full script, I still can't get this working even with your code. It's driving me insane!

avatar image Orami · Aug 13, 2015 at 09:21 PM 0
Share

I also am having problems with getting a handle to the FPS controller. I have even tried making a public GameObject and dragging the SOB to it. Still getting a null reference exception in my code.

avatar image Jasper_Moore · Jul 15, 2016 at 03:14 PM 1
Share

Alternatively,

 GetComponent<UnityStandardAssets.Characters.FirstPerson.FirstPersonController>().enabled = false;
avatar image wod16210666 Jasper_Moore · Jun 01, 2018 at 11:17 PM 0
Share

Thank you, out of all these answers yours worked perfectly ^_^

avatar image
1

Answer by n12901 · Feb 09, 2019 at 03:52 PM

Here's an answer to @XxNexusxX's question.

In FirstPersonController.cs, change line 21 to:

  [SerializeField] public MouseLook m_MouseLook;

Now, to unlock the mouse, use:

 player.m_MouseLook.SetCursorLock(false);
 player.m_MouseLook.UpdateCursorLock();

where player is the FPSController.

Comment
Add comment · Show 1 · 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 Kzapas · Jul 01, 2020 at 04:07 AM 0
Share

Thank you!

avatar image
0

Answer by XxNexusxX · Apr 02, 2017 at 09:53 AM

@Jasper_Moore Great! Now, is there a way for you to make it so that it automatically makes the cursor come on. so i can press a respawn button on a gui that apears?

Comment
Add comment · 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
0

Answer by Israel1994 · Jul 30, 2017 at 08:55 PM

Private Void Cambio de la linea 30 a la 36, así resolví el problema ahora todo anda excelente


pausa-menu-cmara-fps-desactivado.png (61.7 kB)
pausa-menu-cmara-fps-desactivado.png (74.6 kB)
Comment
Add comment · 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

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

28 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

Related Questions

disable touch when game is paused(Time.timeScale = 0) 1 Answer

Enable first person controller after a sequence 0 Answers

Secoundary/GUI camera not pausing/disabeling. 1 Answer

script from another 1 Answer

Cursor help 1 Answer


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