- Home /
How to make an open and close box?,How to make open and close a box?
I got a code, what i written for open and close an inventory panel, but it doesn't works. I dont know how to check gameobject enabled or disabled status.. help me please
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class playerManager : MonoBehaviour {
public GameObject iventory;
public bool iventoryOpen;
void Start () {
iventory.SetActive(false);
iventoryOpen = false;
}
void Update () {
if(iventoryOpen == false && Input.GetKeyDown(KeyCode.E))
{
Debug.Log("Megnyit");
iventoryOpen = true;
iventory.SetActive(true);
}
if (iventoryOpen == true && Input.GetKeyDown(KeyCode.E))
{
iventoryOpen = false;
Debug.Log("Valami nem oké");
iventory.SetActive(false);
}
}
}
Comment
Is the inventory
gameObject holding your player$$anonymous$$anager
script? If so, disabling the gameObject (in the Start
method) also disable your script, thus, preventing Update
from running