I currently have a very simple code that simply deactivates all canvas in the scene, and then activates the ones that I want to keep active (anyways, feel free to suggest any method to optimize this).
It is working exactly as I want, but I don’t fell its right needing to attach it to a GameObject for this to work. So I thought on doing something like calling DisableCanvas(somethingToKeepActive) but I don’t know how to do this in a nice way.
Here is my code:
`
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DisableCanvas : MonoBehaviour
{
public List<GameObject> canvasToKeepActive = new List<GameObject> ();
private GameObject [] allCanvas;
private void Awake ()
{
allCanvas = GameObject.FindGameObjectsWithTag ( "Canvas" );
// Disables all canvas in scene
for ( int i = 0 ; i < allCanvas.Length ; i++ )
{
allCanvas [ i ].gameObject.SetActive ( false );
}
// Activates the selected canvas
for ( int i = 0 ; i < canvasToKeepActive.Count ; i++ )
{
canvasToKeepActive [ i ].SetActive ( true );
}
}
}