tspaddock / bizpadtech

0 stars 0 forks source link

Please Help! Open and close menu on click #1

Closed tspaddock closed 6 years ago

tspaddock commented 7 years ago

Please Help! Maybe I am doing something wrong but I've implemented this script and the only thing that is happening is my canvas (Canvas1) is closing "if" I have it active within the Hierarchy. If I click on my gameObject (Monkey1), that the below script is assigned to, nothing happens. The way my hierarchy is set up is that my canvas (Canvas1) is a child of the gameObject (Monkey1). Here is my code.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using HoloToolkit.Unity.InputModule;

public class InteractibleManager: MonoBehaviour, IInputClickHandler
{
    public GameObject Canvas1;

    bool destroy = false;

    private void Start()
    {
        InputManager.Instance.AddGlobalListener(gameObject);
    }

    public void OnInputClicked(InputClickedEventData eventData)
    {
        if (!destroy)
        {
        Canvas1.SetActive(true);
        destroy = true;
        }
        else
        {
        Destroy(Canvas1);
        //Also destroy this script. We dont need it anymore since the canvas is destroyed!
        Destroy(this);
        }
    }
}

I was hoping to have the canvas non active until the gameObject is clicked on and then destroyed once it is clicked on again. This could happen over and over sort of like a menu. I really appreciate anyones help in this!!!