- Home /
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.
GameObject.Find("Player").GetComponent<FirstPersonController>().enabled = false;
You forgot the () at the end of the GetComponent()
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.
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 ().
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.
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
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.
Hey could you post your full script, I still can't get this working even with your code. It's driving me insane!
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.
Alternatively,
GetComponent<UnityStandardAssets.Characters.FirstPerson.FirstPersonController>().enabled = false;
Thank you, out of all these answers yours worked perfectly ^_^
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.
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?
Answer by Israel1994 · Jul 30, 2017 at 08:55 PM
Your answer
Follow this Question
Related Questions
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
Disable a script from another script 2 Answers