- Home /
How to hide Canvas?
Hi, I made an Inventory System. The problem is that if I write "Canvas.SetActive(false);", I can't use the Script on it. But I have to use the attached script.
I think instead of setting the SetActive state to false, I have to change the alpha channel of the canvas.
How can I change this?(I'm using the new UI)
Thanks for help!
Answer by Flightkick · Jun 23, 2015 at 10:20 AM
If I understand you correctly you have a canvas in which you display your inventory and you want to be able to hide/show this inventory.
To be able to achieve this it might be worth adding your inventory objects to an empty gameobject which you name Inventory (see pic).
You can then toggle this GameObject via SetActive()
Example (whereas Inventory is a the empty gameobject where your inventory items reside in):
private void ToggleInventory()
{
Inventory.SetActive(!Inventory.activeSelf);
}
The problem that the Inventory has a script. And I have to have access to the script even the Inventory is not active...
So your method dont work
I think you didnt understand my problem...I can't deactivate the canvas or the Inventory becaus the Inventory has a Script. Another Script has to use the Inventoryscript even when the inventory is deactivated. So I have to hide it without deactivate it... How can I do this?