Newbie here. Using default First Person Controller prefab.
Whenever I move my mouse over to the screen-space UI, the camera obviously moves. I want to use a keyboard toggle to turn MouseLook off and on as needed. I know MouseLook exists in both the First Person Controller and the actual Camera.
Is there a script that will do this already? I have seen numerous threads on the topic, but all are partial or don’t seem to work (perhaps I am missing something). Anyone have a good one they can share?
Just from the top of my head, didnt test it.
There are probally easier / more efficient ways to do it, but this should work for now. Make sure to change the line:
if (Input.GetKey(KeyCode.P)) {
To your preferred Key
Create a new script named: DisableMouseLook (Or something different, but then make sure to rename it in the script as well). Attach it to your FPS Controller:
using UnityEngine;
public class DisableMouseLook : MonoBehaviour {
MouseLook mouseLookController;
MouseLook mouseLookCamera;
void Start () {
mouseLookController = GetComponent<MouseLook> ();
mouseLookCamera = Camera.main.GetComponent<MouseLook> ();
}
void Update () {
if (Input.GetKey(KeyCode.P)) {
mouseLookController.enabled = false;
mouseLookCamera.enabled = false;
} else {
mouseLookController.enabled = true;
mouseLookCamera.enabled = true;
}
}
}
This code works as such:
While holding down the letter P, the mouselook components are disabled.
1 Like
Hmmm… mouseLook doesn’t seem to be working any more in Unity 5. Anyone have an idea why?
Anyone have an idea on this?