O'Reilly logo

HoloLens Beginner’s Guide by Jason Odom

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Any object can be an interface object

We are not limited to the Unity UI to make interfaces in Unity, and to prove that point, we will use the ball object itself to affect the scene. While we have seen this in the past, this lesson is worth repeating:

  1. Select the Ball object and click on Add Component.
  2. Select NewScript and type PowerSwitch into the NewScript dialog.
  3. Click on Create and then on Add.

Here is the code for that script file; either type it out or copy and paste it and name the file PowerSwitch.cs:

using UnityEngine; 
using System.Collections; 

public class PowerSwitch : MonoBehaviour { 

    public GameObject go; 

    void OnSelect() 
    { 

        if(go.activeSelf) 
        { 
            go.SetActive(false); 

        } 
        else 
        { 
            go.SetActive(true); 

        } 

    } 
} 

This code uses a single public ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required