> For the complete documentation index, see [llms.txt](https://kdoore.gitbook.io/cs2335/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kdoore.gitbook.io/cs2335/project-2-dialog/hideshow-panel-script.md).

# Hide\_Show\_Panel Script

## CanvasGroup Component to hide UI elements

The following script can be put on any UI gameObject to control whether it is hidden when the scene starts.&#x20;

In Project2, we'll use this script on panel associated with scene dialog. \
With this attached script will be hidden when the scene is initially loaded.

This script can be used on the OptionPanel which controls buttons for changing scenes. A checkbox in the inspector provides an option to have the panel start in open state when the scene loads.

![](/files/-MK_NBqMTSvjq36gm1Lq)

**The Panel must have a CanvasGroup Component.**&#x20;

When working with [SimpleDialog](https://github.com/kdoore/cs2335_v2/tree/e629ce99d3c4e27e0dc9a8b416a206a1d7051d22/simple-dialog-prefab.md), or [DialogManager](/cs2335/project-2-dialog/dialogmanagerconvlist.md), the OptionPanel should be set as the Next Panel To Open in the SimpleDialog or DialogManager script.

```java
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Hide_Show_Panel : MonoBehaviour
{

    CanvasGroup panelCG; //must be on same gameObject as this script

    public bool showOnStart = false; //default is hidden
    public Button closeButton; //clicking will hide
    public Button openButton; //clicking will show
    public CanvasGroup nextPanelToOpen;

    // Use this for initialization
    void Start()
    {
        panelCG = GetComponent<CanvasGroup>(); //must have CanvasGroup component

        if (!showOnStart)
        {
            HidePanel(); //hide at start
        }
        else
        {
            ShowPanel(); //show at start
        }
        //if buttons are set in inspector, configure to open/close panel 
        if (closeButton != null)
        {
            closeButton.onClick.AddListener(HidePanel);
        }
        if (openButton != null)
        {
            closeButton.onClick.AddListener(ShowPanel);
        }

    }

    public void ShowPanel()
    {
        Utility.ShowCG(panelCG);
    }

    public void HidePanel()
    {
        Utility.HideCG(panelCG);
    }

    public void OpenNextPanel()
    {
        if( nextPanelToOpen != null)
        {
            Utility.ShowCG(nextPanelToOpen);
        }
    }
}

```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://kdoore.gitbook.io/cs2335/project-2-dialog/hideshow-panel-script.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
