Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Hide GameObject from prefab

Discussion in 'Prefabs' started by Lord_Enzo, Jun 14, 2021.

  1. Lord_Enzo

    Lord_Enzo

    Joined:
    Apr 30, 2021
    Posts:
    1
    I have a problem with a prefab and its GameObject. You will see I want to hide the last GameObject (1) that you can see in the image. But I don't know how, since I've tried to save it in a variable but it gives me instance error. How should I hide it? In the else I have managed to hide the text that contains the gameobject (it is what is put), but what really interests me is to hide it whole.

    upload_2021-6-14_11-38-58.png

    Code (CSharp):
    1. public void AddItemToList(Member member)
    2.         {
    3.             GameObject memberItemObj = prefab;
    4.             GameObject obj = Instantiate(memberItemObj, content.transform);
    5.  
    6.             MemberItem memberItem = obj.GetComponent<MemberItem>();
    7.  
    8.             memberItem.name.text = member.name;
    9.             memberItem.member = member;
    10.             memberItem.chipsText.SetText(member.chips.ToString());
    11.  
    12.             if (member.isOwner || member.isAdministrator)
    13.             {
    14.                 memberItem.chipsClubText.SetText(member.clubChips.ToString());
    15.             }
    16.             else
    17.             {
    18.                 memberItem.chipsClubText.gameObject.SetActive(false);
    19.  
    20.             }
    21. }
     
    Last edited: Jun 14, 2021