I am having trouble trying to use this code in Unity 5
usually uses in version 4 ![]()
can help me fix it?
I am having trouble trying to use this code in Unity 5
usually uses in version 4 ![]()
can help me fix it?
First up, the description for this sub-forum is pretty clear that this isn’t a support area. This should be in the Scripting area.
Secondly, what does “don’t work” mean? Does your computer lock up? Do you get an error message in the console? Do you get spontaneously Rick-Rolled whenever the code runs? We need to know more to be able to help.
Thirdly, see my sig for an awesome link.
Finally, I’d suggest breaking that line down into each of its components and making sure that each piece is working as intended. Does gameObject.Find(“Char_Configuration”) actually find the correct GameObject? Does GetComponent(…) find the component?
First and second
Thanks for the lesson will not again repeat the same mistake ![]()
Finally …
Here’s the code I’m trying to use
#pragma strict
var pauseCanvas = Canvas;
function Start () {
Screen.lockCursor = true;
Screen.showCursor = false;
}
function Update ()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
(gameObject.Find(“Char_Configuration”).GetComponent (“MouseLook”) as MonoBehaviour).enabled = false;
(gameObject.Find(“Camera_Configuration”).GetComponent (“MouseLook”) as MonoBehaviour).enabled = false;
pauseCanvas.enabled = true;
Time.timeScale = 0;
Screen.lockCursor = false;
Screen.showCursor = true;
}
}
function ReturnGame () {
}
I looked and all is right with “Char_Configuration” and "Camera_Configuration
I’m trying to get my pause menu only opens with the “escape” button

Ok, take a look at that error message:
You’re (inadvertently) treating something like one type of thing when it is another. Breaking out the Find and GetComponent into their own statements will help narrow down exactly where the issue is.
I think the string version of GetComponent was deprecated in Unity 5? Maybe?
But @angrypenguin is right. Breaking the line up will help isolate the issue.
You should also cache your references. It will make the code easier to read and more preformant.