- Home /
C# How do I toggle MouseLook in game?
I have a game in which the player interacts with NPC's by selecting GUI buttons when dialogue is initiated. Because of this, I need to be able to toggle the mouselook script off in the first person controller when dialogue is initiated. Unfortunately, any attempt to reference the Mouselook script by way of ".GetComponent()" gives the response, "error cs0103: The name 'MouseLook' does not exist in the current context"
Here is the code I'm using:
private void DisableMouseLook(bool enable)
{
//First person Controller is tagged "Player"
GameObject FPC= GameObject.FindWithTag("Player");
FPC.transform.GetComponent<MouseLook>().enabled = enable;
}
The word MouseLook is in red in MonoDevelop, and mousing over it gives the above error. Any help would be greatly appreciated, as not many other people seem to have this problem.
Answer by Maksimusbed · May 05, 2015 at 12:03 PM
You have to add - using UnityStandardAssets.Characters.FirstPerson;
and for example
public FirstPersonController fps;
void DisableMouseLook(bool enable) { fps.enabled = false; }
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Unity 5 access First Person Controller Mouse Look Sensitivity via script 3 Answers
Accessing RigidbodyFirstPersonController 0 Answers