Hello everyone.

We have decided to phase out the Mixed Reality Forums over the next few months in favor of other ways to connect with us.

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.

The plan between now and the beginning of May is to clean up old, unanswered questions that are no longer relevant. The forums will remain open and usable.

On May 1st we will be locking the forums to new posts and replies. They will remain available for another three months for the purposes of searching them, and then they will be closed altogether on August 1st.

So, where does that leave our awesome community to ask questions? Well, there are a few places we want to engage with you. 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. And always feel free to hit us up on Twitter @MxdRealityDev.

How to display text when selecting an object

I'm trying to build a simple app that displays text above a hologram once I gaze at and air-tap to select that hologram. Can someone help me out? I'm new to Hololens development. Currently using the Holotoolkit, but don't know how to proceed.

I have the "Tap Responder" script attached to my holograms, as well as the "Tap To Place" script (however the latter is not working). I've also included the InputManager, EventSystem, SpatialMapping and RemoteMapping prefabs in a blank object I've called "Managers".

Best Answers

Answers

  • @keljed said:
    1. Use an InputManager and a Cursor
    2. Create a prefab for your text (maybe based on HoloToolkit UITextPrefab)
    3. create and attach a script that implements IInputClickHandler to your hologram/gameobject
    4. Associate your text prefab with the script
    5. instantiate your prefab and place it above your gameobject on click event

    `
    public class ShowOnTap : MonoBehaviour, IInputClickHandler
    {
    public GameObject TextPrefab;

        public void OnInputClicked(InputEventData eventData)
        {
            var text = Instantiate(TextPrefab);
            var position = gameObject.transform.position;
    
            text.gameObject.transform.position = new Vector3(position.x, position.y + 0.1f, position.z);
        }
    }
    

    `

    @keljed Where do I place the UITextPreFab - In the hierarchy, or as a child of my hologram? If the prefab is called UITextPrefab, do i need to call it that specifically in the code above?

  • edited June 2017

    Hi, I had the same question and I realized that you can query the object "under" the Gaze like this:

    if (GazeManager.Instance.IsGazingAtObject)
    {
        if (GazeManager.Instance.HitObject.name == "BlahBlah")
        {
            DoSomething();
        }
    }
    
  • @sgambolati said:
    Hi, I had the same question and I realized that you can query the object "under" the Gaze like this:

    if (GazeManager.Instance.IsGazingAtObject)
    {
        if (GazeManager.Instance.HitObject.name == "BlahBlah")
        {
            DoSomething();
        }
    }
    

    Hi sgambolati,
    I also want to check the name of the gazed object like you suggested, but I got a null reference exception.
    In my scene I have a manager gameobject with all the manager scripts (e.g. gaze, gesture,...). Additionally I introduced another gameobject "VoiceManager", which shows a text when a specific object is gazed.
    When I run the program, I got a NullReferenceException, but I "wired" the text and the RawImage.

    This is my code:
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using HoloToolkit.Unity.InputModule;
    using UnityEngine.UI;

    public class VoiceManager_Main : MonoBehaviour {

    public Text interaction_hint;
    public RawImage interaction_micro;
    
    public Text communication_hint;
    public RawImage communication_micro;
    
    public Text help_hint;
    public RawImage help_micro;
    
    
    
    
    
    
    
    void Reset()
    {
        interaction_hint.GetComponentInChildren<Text>().text = "";
        interaction_micro.gameObject.SetActive(false);
    
        communication_hint.GetComponentInChildren<Text>().text = "";
        communication_micro.gameObject.SetActive(false);
    
        help_hint.GetComponentInChildren<Text>().text = "";
        help_micro.gameObject.SetActive(false);
    
    }
    
    
    
    // Use this for initialization
    void Start ()
    {
    
        Reset();             
    
    }
    
    // Update is called once per frame
    void Update ()
    {
    
       Reset();
    
        if (GazeManager.Instance.HitObject.name == "Interaction_Button")
            {
    
    
                communication_hint.GetComponentInChildren<Text>().text = "   'Open Communication'";
                communication_micro.gameObject.SetActive(true);
    
    
    
            }
    
            else if (GazeManager.Instance.HitObject.name == "Help_Button")
            {
    
                help_hint.GetComponentInChildren<Text>().text = "   'Show Information'";
                help_micro.gameObject.SetActive(true);
    
    
    
            }
    
            else if (GazeManager.Instance.HitObject.name == "Interaction_Button")
            {
    
                interaction_hint.GetComponentInChildren<Text>().text = "   'Start Interaction'";
                interaction_micro.gameObject.SetActive(true);
    
    
    
            }
    
    }
    

    }

  • dbarrettdbarrett ✭✭✭

    Hi @ChristophMarko , it is probably because you are trying to get the HitObject.name but that might be null. I wouldn't go in this direction unless you really have to. Instead, if you want to "Do Something" to an object you are looking at then, you should attach a script to that object and inherit from the IFocusable script. Whenever you look at the object, the OnFocusEnter will be called.

    AR Developer

  • Hi @dbarrett, thank you for your reply and your information. My intention was to compare the name of the gazed object with the name of a button. When the right button was gazed a text will be shown, other wise nothing will be shown.
    In my scene I have 3 buttons and the funny thing is that it doesn't work with the first button but for the other 2 buttons it worked quite good.

  • It the simplest way, and I've not read the above ... there is a raycast that is performed, and when the object is aligned with the ray ... the one your eyes define ... then the object has an event sent to it ... and can respond ... for instance by lighting up some specific text ... in your event handler for that object.

    This is down into the details ... if you're up at the toolbox level.

    Signed, a monkey minded simpleton ... just a fool ... don't read posts by Utekai either ... I mean likely you can't most are hidden.

Sign In or Register to comment.