- Home /
Question by
n00banator912 · Nov 16, 2015 at 08:42 AM ·
guibuttonmenupausepause menu
GUI Buttons not working after scene transition
so, I found this tutorial on youtube and fit the code to work in my game.
var pauseCanvas : Canvas;
var playerObject : GameObject;
var cameraObject : GameObject;
function Start (){
pauseCanvas = GameObject.Find("pauseCanvas").GetComponent("Canvas");
pauseCanvas.enabled = false;
}
function Update (){
if (Input.GetKeyDown("escape")){
playerObject.GetComponent("MouseLook").enabled = false;
playerObject.GetComponent("CharacterMotor").enabled = false;
playerObject.GetComponent("FPSInputController").enabled = false;
cameraObject.GetComponent("MouseLook").enabled = false;
pauseCanvas.enabled = true;
Screen.lockCursor = false;
Screen.showCursor = true;
}
}
function Resume (){
pauseCanvas.enabled = false;
Screen.lockCursor = true;
Screen.showCursor = false;
playerObject.GetComponent("MouseLook").enabled = true;
playerObject.GetComponent("CharacterMotor").enabled = true;
cameraObject.GetComponent("MouseLook").enabled = true;
playerObject.GetComponent("FPSInputController").enabled = true;
}
the problem lies in scene transitions. pauseCanvas is attached to a persistent object, but when I go from scene 0 (main menu) to scene 1(level 1) the buttons do not work.
The buttons do work under normal circumstances as tested on my "charTest" level.
Comment
Did you manage to solve this? I am having the same issue...
I think what you need is a script that would call this script ins$$anonymous$$d.