- Home /
This question was
closed Aug 28, 2017 at 01:28 PM by
Trick_Shot_Magic for the following reason:
The question is answered, right answer was accepted
Question by
Trick_Shot_Magic · Aug 28, 2017 at 01:06 PM ·
scripting problemcanvasactivatedeactivate
want to activate and deactivate a canvas by script
made up this code but it is having no effect:
public GameObject canvas;
bool canvasactive;
bool islocked;
void Start () {
SetCursorLock (!islocked);
}
void SetCursorLock (bool islocked)
{
this.islocked = islocked;
Screen.lockCursor = islocked;
}
void Update () {
if (Input.GetKeyDown (KeyCode.Escape)) {
canvasactive = !canvasactive;
canvas.SetActive (canvasactive);
}
}
Comment
Answer by efeguclu · Aug 28, 2017 at 01:14 PM
function called if you press escape only I think you know that but if its not the problem you may not attached this script to any object?
attached it to a empty game object, and added the canvas in the public gameobject