Object/UI show hide
- Object activation state control show hide
gameObject.SetActive(true);
gameObject.SetActive(false);
When the bool value is true, the object is displayed;
when the bool value is false, the object is hidden
- Get the material component control to show hidden
(1) objects
GameObject.GetComponent<MeshRenderer>().enabled=true;
GameObject.GetComponent<MeshRenderer>().enabled=false;
When the bool value is true, the object is displayed;
when the bool value is false, the object is hidden
(2)UI
GameObject.GetComponent<Image>().enabled = true;
GameObject.GetComponent<Image>().enabled = false;
When the bool value is true, the object is displayed;
when the bool value is false, the object is hidden
3. The Canvas Group component controls the display and hiding of the UI. Adding
method Search the parameter Alpha in the
Canvas Group component : controls the transparency, 0 is completely transparent, 1 is completely opaque ; Block Raycasts: Whether to accept ray detection Ignore Parent Groups: Whether to respond to the parent group code as follows:
canvasGroup.alpha = 1;
canvasGroup.interactable = true;
anvasGroup.blocksRaycasts = true;