- Home /
[c#] first script isnt disabling canvas and player cant move (issue with first script)
Hi, I have made a script that enables a canvas if a certain gameobject isnt active in the hierarchy
here is the first script
public void Update()
{
if (trigger.activeInHierarchy == false)
{
canvasToShow.enabled = true;
}
else if(trigger.activeInHierarchy == true)
{
canvasToShow.enabled = false;
}
}
the second script is a script that disables player movement when the canvas is enabled.
public void Start() { if(canvas.enabled == true) { controller.enabled = false; Cursor.lockState = CursorLockMode.None; Cursor.visible = true; }
else if(canvas.enabled == false)
{
controller.enabled = true;
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
}
my problem is that when i start the game i cant move because for some reason the first script isnt disabling the canvas.
Are you sure that "trigger" object is active in hierarchy i.e. it and every its parent are active?
Answer by ray2yar · Jan 08, 2019 at 10:42 PM
Maybe the problem is that you're checking for the change in state in the start () but the change isn't made until the first update call.