Creating Interaction in a Scene
Tutorial
·
intermediate
·
+0XP
·
15 mins
·
Unity Technologies
In this tutorial, we’ll explore a method for adding functionality at runtime by creating a UI that controls the lights in the Scene.
Languages available:
1. Introduction
The Reflect Viewer loads a model at runtime that is not available in the Game Scene when the game is not running. This makes it difficult to add additional scripts and interactions to the model. In this tutorial, we’ll explore a method for adding functionality at runtime by creating a UI that controls the lights in the Scene.
For this tutorial, you will need:
- The Reflect Viewer project downloaded from Github GitHub - Unity-Technologies/com.unity.reflect.viewer: Unity Reflect Viewer
- A Pro license for the Unity Editor
- A Reflect project that contains lights
- The “CreatingInteractionintheScene_Resources.unitypackage” file that is part of this tutorial.
2. Setting up the Interaction
1. Open the Reflect project downloaded from Github and open the Reflect scene.

2. Expand UI Root in the Hierarchy.

3. Right-click on the UI root element and select UI > Image.

4. Select the image element and in the Inspector, change the Source Image to “Lightbulb”.

5. Change the name of the Image element to “LightSwitchIcon” and move it to a position on the left of the UI screen.

6. Drag the LightControls script from Assets > Scripts onto the UI Root object.

7. This script contains two methods, one for switching the lights off and one for switching the lights on. The script runs through all of the child objects of the object it was attached to. When it finds an object of the type specified — in this case, a light — it toggles the Enabled property on or off.
The Root object we applied the script to is a placeholder for the model that will be imported at runtime. When the runtime model is imported, it will be created as a child of this Root object, regardless of which project you open.
8. Select the LighSwitchIcon object and add a Button component, then add an On Click () event by selecting the + icon.

9. Drag the Root object into the “None (Object)” slot

10. Select the “No Function” dropdown menu and then select ReflectWorkshop. LightsControls > LightSwitch ()

11. Run the project and open any previously created project that contains lights. Select the LightSwitchIcon and lights in the project should be switched on and off every time that you click the icon.
3. Next Steps
One of the problems with working with Reflect Viewer runtime models is accessing the objects at runtime. Since the model is only loaded at runtime, you can’t load scripts on specific objects beforehand. Using the Root object and then using the “GetComponentsInChildren()” method, you can filter through the imported model at runtime and add functionality to specific objects. This tutorial covered the solution to that problem and will allow you to create your own custom controls.