Hello everyone.

The Mixed Reality Forums here are no longer being used or maintained.

There are a few other places we would like to direct you to for support, both from Microsoft and from the community.

The first way we want to connect with you is our mixed reality developer program, which you can sign up for at https://aka.ms/IWantMR.

For technical questions, please use Stack Overflow, and tag your questions using either hololens or windows-mixed-reality.

If you want to join in discussions, please do so in the HoloDevelopers Slack, which you can join by going to https://aka.ms/holodevelopers, or in our Microsoft Tech Communities forums at https://techcommunity.microsoft.com/t5/mixed-reality/ct-p/MicrosoftMixedReality.

And always feel free to hit us up on Twitter @MxdRealityDev.
Options

Canvas to appear on Airtap Gesture using IInputClickHandler

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

Best Answer

Answers

  • Options
    ReeleyReeley ✭✭✭

    This will activate your Canvas on the first airtap and destroy it on the second airtap:

    using UnityEngine;
    using HoloToolkit.Unity.InputModule;
    
    public class CanvasManager : MonoBehaviour, IInputClickHandler
    {
        public GameObject canvas;
    
        bool destroy = false;
    
        private void Start()
        {
            InputManager.Instance.AddGlobalListener(gameObject);
        }
    
        public void OnInputClicked(InputClickedEventData eventData)
        {
            if (!destroy)
            {
                canvas.SetActive(true);
                destroy = true;
            }
            else
            {
                Destroy(canvas);
                //Also destroy this script. We dont need it anymore since the canvas is destroyed!
                Destroy(this);
            }
        }
    }
    

    Just attach this script to an empty gameobject and assign your canvas

  • Options

    Thanks for getting back to me! You are a Ninja!
    Maybe I am doing something wrong but I implemented your 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 your script is assigned to after that, 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 your help in this!!!

  • Options

    Works perfectly! Thank you very much for your help! I am in your dept. :)

Sign In or Register to comment.