Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Menu panels show in game by default as open

i’m making a 2D game and my Menu panels are showing when i press play on unity they show as opened is there anyway to make them closed and only show when i press on menu button. this is the picture from the game:

menu open

And this is the script for panel opener when i press the menu button:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PanelOpener : MonoBehaviour
{

    public GameObject Panel;


    public void OpenPanle()
    {

        if (Panel != null)
        {

            bool isActive = Panel.activeSelf;
            Panel.SetActive(!isActive);

        }
    }
}

>Solution :

Disable panels at start with a:

    private void Awake(){
        Panel.SetActive(false);
    }

Complete code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PanelOpener : MonoBehaviour
{

    public GameObject Panel;

    private void Awake(){
        Panel.SetActive(false);
    }

    public void OpenPanle()
    {

        if (Panel != null)
        {

            bool isActive = Panel.activeSelf;
            Panel.SetActive(!isActive);

        }
    }
}

Get yourself familiar with MonoBehaviour functions like Start, Awake, Update, FixedUpdate in the future.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading