I am trying to figure out how to freeze the first person controller while the user is presented with a menu. I am used the mouseLock variable in the script MouseLook, but for the life of me I cant figure out why I keep getting this error, “Unknown identifier: ‘MouseLook’”. Here is my script…
var menuSkin : GUISkin;
static var escapeMenuOn : boolean = false;
static var escapeMenuUsed : boolean = false;
static var script =MouseLook;
The rest of the code is just an OnGUI function with some buttons and the like. The error is on the line where I assigned the var “script” to MouseLook. I even tried the longhand way, instead of script.mouseLock, I tried MouseLook.mouseLock. Nothing seems to be working…
var mouseLook : MouseLook;
function Start() {
mouseLook = gameObject.GetComponent(MouseLook);
}
function LateUpdate(){
if (Input.GetKeyDown("escape"))
{
mouseLook.enabled = false;
//do your menu function call,etc in here too
}
}
Nothing seems to be wrong with the rest of the code. It just looks like it cant find the script MouseLook, the same error you would get if you defined a script that doesnt exist.
Here is my complete code.
var menuSkin : GUISkin;
static var escapeMenuOn : boolean = false;
static var escapeMenuUsed : boolean = false;
var script : MouseLook;
function Start() {
mouseLook = gameObject.GetComponent(MouseLook);
}
function OnGUI () {
GUI.skin = menuSkin;
if(escapeMenuOn== true){
Screen.showCursor = true;
//script.mouseLock = true;
Time.timeScale = 0.0;
escapeMenuUsed = true;
GUI.Label (Rect (Screen.width/2 -20, Screen.height/2 - 100, 100, 20), "Paused");
GUILayout.BeginArea (Rect (Screen.width/2 - 125, Screen.height/2 - 75, 250, 250));
if(GUILayout.Button ("Return to Game"))
{
escapeMenuOn = false;
escapeMenuUsed = false;
MouseLook.mouseLock = false;
Screen.showCursor = false;
Time.timeScale = 1;
}
if(GUILayout.Button ("Load Game"))
{
escapeMenuOn = false;
LoadSaveGUI.loadSaveGUI = true;
LoadSaveGUI.loadMenuOn = true;
}
if(GUILayout.Button ("Save Game"))
{
escapeMenuOn = false;
LoadSaveGUI.loadSaveGUI = true;
LoadSaveGUI.saveMenuOn = true;
}
if(GUILayout.Button ("Options"))
{
escapeMenuOn = false;
OptionsMenu.optionsMenuOn = true;
}
if(GUILayout.Button ("Quit to Main Menu"))
{
escapeMenuOn = false;
escapeMenuUsed = false;
//script.mouseLock = false;
Time.timeScale = 1;
Application.LoadLevel(0);
LoadSaveGUI.mainMenuOn = true;
}
GUILayout.EndArea ();
}
}
If it’s generating errors that you normally get when it cannot find a script, have you put the mouselook script into one of the early compile folders and left your menu script above it in the heirarchy?
Don’t forget the cs needs to be compiled before it’s accessable by your js, even if the object it’s attached to exists already (Quirk of Unity)
Make sure mouselook.cs is in one of the early-compiled folders and keep your pausemenu.js in the root.
MouseLook is in the StandardAssets/CameraScripts folder, and my pause menu is in the root. I tried every other combination to no avail… Is there another way to freeze fps rotation that doesnt involve mouselook? Weird error, I copied a solution from another topic in here that works fine in a new project, but something is wrong here. Almost like it cant find Mouse Look, but in-game Mouse Look works fine…
You were right, I must have bumped the standard assets folder under another. It has to be very alone for things to work right. Thanks for the quick reply! 
You could change:
mouseLook = gameObject.GetComponent(MouseLook);
for:
mouseLook = Camera.main.GetComponent(MouseLook);
As camera objects have a call all to themselves