tspaddock / noway

0 stars 0 forks source link

Canvas to appear on Airtap Gesture using IInputClickHandler #3

Open tspaddock opened 7 years ago

tspaddock commented 7 years ago

Hi, For some reason I am not able to locate a script that can help me activate and destroy a menu using Airtap. I have already built the menu using a canvas and I have positioned it appropriately. Can anyone point me in the direction of the appropriate c# script? Thanks

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!!!