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

Hide and unhide of mesh - scripting

Beginner here: I working from the Origami tutorial, have added an object, 5 layers.

When placing the cursor on 1 of the layers I want to hide this layer. And unhide it again.

Please advice how to script this.

Also, where can I go to learn writing these simple scripts myself?

Thanks!

Answers

  • Options

    @Cyberfish_Fred

    Here is are a couple of simple hide/show routines for hiding and showing the entire game object and in this form would be included in a script on the particular gameobject that you want to show/hide. That is one approach.

        public void OnHide()
        {
            Renderer[] rendererArray = this.gameObject.GetComponentsInChildren<Renderer>();
            foreach (Renderer r in rendererArray)
            {
                r.enabled = false;
            }          
        }
    
        public void OnShow()
        {
            Renderer[] rendererArray = this.gameObject.GetComponentsInChildren<Renderer>();
            foreach (Renderer r in rendererArray)
            {
                r.enabled = true;
            }            
        }
    

    You mentioned layers, depending on how you create and design your "layers" here is another approach using Unities layers concept where the script below would be attached to your main camera to toggle on and off a layer, in this case the "Furniture" layer of a house model:

        public void OnHideFurniture()
        {
            Camera.main.cullingMask ^= 1 << LayerMask.NameToLayer("Furniture");
        }
    
        public void OnShowFurniture()
        {
            Camera.main.cullingMask ^= 1 << LayerMask.NameToLayer("Furniture");
        }
    

    Note this was a quick and dirty implementation that is simple and stupid. If the user gives the voice command to show twice in a row it ends up toggling on and off. However, it demonstrates the concept and you can easily code logic to be more intelligent.

    As for resources to learn Unity scripting;

    Unity has great resources on their site.

    Lynda.com has Unity courseware.

    YouTube has lots of useful stuff.

    Here are two useful series on creative coding in unity.

    Google is your friend.

    HTH.

    Windows Holographic User Group Redmond

    WinHUGR.org - - - - - - - - - - - - - - - - - - @WinHUGR
    WinHUGR YouTube Channel -- live streamed meetings

  • Options

    Thanks a lot, I hope as a beginner that I can use this. Will try this week!

Sign In or Register to comment.