So I have a basic main menu and subsequent sub-menu. I have pointerEnter set to enable an outline on my text, to show that it’s actively “selected”. I have pointerExit set to disable outline on exit.
I have my menu script attached to the canvas, where all of the buttons / text live. I have the two panels (main menu, options) set to groups in my script so i can show / hide said panels when the appropriate button is clicked (options button, back button).
I want to deselect (turn off the outline) of a button when it’s clicked, so that returning to that screen shows no button currently selected.
I have tried numerous things to see if I could get my script working. At this point my only option is to set each and every button to a variable, but I was hoping I could just grab all outlines (or grab all buttons and find their text / outline component), then turn them off either in a loop (foreach component outline in menugroup) or simply by telling unity to turn off all outlines (kind of like how jQuery can affect all objects in an array at once).
I’m strictly using C# for this learning project, so if you can point me in the right direction, it’d be very helpful.
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class menuScript : MonoBehaviour
{
public GameObject mainPanel;
public GameObject optionsPanel;
private Outline outline;
void Awake()
{
mainPanel.SetActive(true);
optionsPanel.SetActive(false);
}
public void exitGame()
{
#if UNITY_EDITOR
UnityEditor.EditorApplication.isPlaying = false;
#else
Application.Quit();
#endif
}
public void showOptions()
{
mainPanel.SetActive(false);
optionsPanel.SetActive(true);
}
public void showMain()
{
mainPanel.SetActive(true);
optionsPanel.SetActive(false);
}
public void inactiveOutlines()
{
outline = mainPanel.GetComponentInChildren<Outline>();
Debug.Log(outline.IsActive());
Debug.Log(outline);
}
}