- Home /
Preventing the first person controller from rotating
Hi Unity Community
I am trying to prevent the First Person character from rotating via mouse click however I cannot seem to access the appropriate field; how is this supposed to be achieved? I’m currently thinking the best approach might be change the x/y mouse sensitivity variables (held in the MouseLook class) to 0 however I can’t seem to do this.
(FYI I am programming in uJs.)
I have tried accessing the UnityStandardAssets.Characters.FirstPerson namespace but to no avail (returns ‘not found, maybe you forgot to add an assembly namespace’ - what is the appropriate namespace I require?)
I have also tried accessing the field directly (as per existing posts on the issue) via .GetComponent(MouseLook) also to no avail.
What is the best method of achieving this?
Current Code:
import UnityStandardAssets.Characters.FirstPerson;
var browseMenu : GameObject;
var browseMenuButton : GameObject;
var menuActive : boolean;
private var menuMode : boolean;
function Start () {
var fpcScript = gameObject.GetComponent(MouseLook);
}
function setMode()
{
if(!menuMode) //if not in menuMode turn it on
{
browseMenu.SetActive(true);
browseMenuButton.SetActive(true);
MouseLook.XSensitivity = 0;
}
}
Field To Access:
Answer by vdwtanner · Dec 22, 2015 at 08:41 PM
I just modified the code for the first person character to include a couple of public methods that set the x/y sensitivity that I am able to access via broadcast messages. It's not as nice as I'd like, but it certainly does the job.
public void pauseMouseLook(){
m_MouseLook.XSensitivity = 0F;
m_MouseLook.YSensitivity = 0F;
}
public void resumeMouseLook(){
m_MouseLook.XSensitivity=m_MouseLook.oldXS;
m_MouseLook.YSensitivity=m_MouseLook.oldYS;
}
Access with: BroadcastMessage("pauseMouseLook");
or BroadcastMessage("resumeMouseLook");
Unfortunately I can't help with why it doesn't like the namespace since I mainly work in C# when using Unity.