- Home /
camera locks vertical occationally
so i've got a script for locking my camera while the menu is open.... problem is that it "Occationally" and yes... it really is only occationally which is why i'm completely lost here, locks the vertical look but not the horizontal look when i exit the menu again. The thing that throws me off is that sometimes it works just as it should but every other time it just keeps the vertical look locked down.
any thoughts?
#pragma strict
public var menu1 : UnityEngine.Canvas;
public var cam1 : Camera;
function Start () {
}
function Update () {
if (menu1.enabled == true )
{
cam1.GetComponent(MouseLook).enabled = !cam1.GetComponent(MouseLook).enabled;
}
}
Answer by hybridninja18 · Jul 16, 2015 at 03:07 PM
abandoned the idea of locking it while the canvas was enabled, apparantly for some reason that was what was making the issue happen, instead i went for locking it on keypress.
#pragma strict
//Apply this script to both Charactercontroller and Main Camera!
function Update () {
if (Input.GetKeyUp(KeyCode.K)) {
var mouseLook = GetComponent.<MouseLook>();
mouseLook.enabled = !mouseLook.enabled; // Enables and Disables mouselook when K is pressed
}
}
Your answer
Follow this Question
Related Questions
MouseLook movement diagonal stutters... 0 Answers
MouseLook.cs:case of JavaScript 1 Answer
Controlling MouseLook script with keys/joystick 1 Answer
How to lock camera roll in C# 1 Answer