Hello,
I am working on a AR-scene where I have several canvas that are supposed to be disabled after initializing the scene. When a user clicks on a cube within that scene, the canvas ,that also includes a UI sprite, shall become visible again and provide the user with some information.
This is the code I used:
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class ToggleMenu : MonoBehaviour
{
// Invisible and clickable cube that contains the 3D-Model of the fountain
public GameObject fountaincube = null;
// 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 2 out of 4 canvas are still visible after the scene initialized and have to be closed manually ![]()
What am I missing here? The 4 canvas are exatly the same in the hierachy. I have also provided a screenshot from the scene and the editor (Editor_Screenshot_1)
Anyone can help? If you need further information, feel free to ask.
