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);
	}	
}

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?

already working thanks