How to disable all canvas at the start of a scene

I´ve been dealing with an extremly frustrating problem for 2 weeks. The forum couldn´t help yet, so you guys are my last resort.

I have a AR-scene with several canvas, that are supposed to be invisible when the scene was loaded.
This script is used to achieve that:

using UnityEngine;
using UnityEngine.UI;
using System.Collections;
 
public class ToggleMenu : MonoBehaviour
{
    // Canvas that appears when the user clicks on the cube
    public Canvas fountaininfo;
 
    // Switch for visible / not visible setting
    public bool fountainswitch;
 
    // Button, that closes the canvas / makes it invisible again
    public Button fountainclose;
 
 
    // ###################
    // ## Settings at the start  ##
    // ###################
 
    void Start()
    {
        // Assinging the Canvas to this variable
        fountaininfo = fountaininfo.GetComponent<Canvas> ();
 
        // visibility setting at the start
        fountaininfo.enabled = false;
 
        // setting of the switch
        fountainswitch = false;
    }
 
 
    // #######################################
    // ## Function, that makes the button visible on click  ##
    // #######################################
 
    private void OnMouseDown()
    {
        if (fountainswitch == false)                      
            fountaininfo.enabled = true;
            fountainswitch = true;
    }
 
 
    // ################################
    // ## Function that closes the canvas again  ##
    // ################################
 
    public void fountainclose_Press()
    {
        fountaininfo.enabled = false;
        fountainswitch = false;
    }
 
}

However, when the scene has loaded, half of the total number of canvas are visible - although I turned them off in the script - what am I missing here? - I put plenty of hours into finding a solution but I just cant find it :frowning:

@doublemax : himmelherrgott kruzifix, es funktioniert endlich! :smiley: :smiley: :smiley: - Mit der Awake-Funktion, die vor der Startfunktion alles einstellt, klappt alles perfekt!

Vielen vielen vielen Dank! :smiley: - Ich muss mal den debug-Befehl ausprobieren, um zu verstehen, wie du zu deiner Erkenntnis gekommen bist. Viele sonnige Grüße aus Würzburg zurück!

For all the others:
Doublemax´ suggestion fixed this issue. I´ll try if switching the bool-condition within the OnMouseDown-Code is necessary. I only built it in to emulate a switch :smiley:

From what I can see it should work… You mention multiple canvases though. Are they children of this canvas referenced in the script? If so then you could simply disable each child canvas as well.

    foreach(Canvas i in fountaininfo.gameObject.GetComponentsInChildren<Canvas>())
    {
           //This is the canvas component and not the GameObject. 
           // To disable the GameObject you have to use yourGameObject.SetActive(bool);.
           i.enabled = false; 
    }

In your script you are only disabling the canvas component. This won’t have any affect on the children or that GameObject.

Hope this helps :slight_smile: