Now that we have a script that uses the component, let's add it to our scene as a new object. Return to the editor where we last left off and continue as follows:
- Open the HelloAR scene. From the menu, select File | Save as and save the scene as Main in the Assets/ARCoreML folder.
- Find and select First Person Camera in the Hierarchy window. Remember that you can use the search panel.
- Right-click (Ctrl + Click on Mac) on the First Person Camera and from the context menu, select Create Empty. Name the object as Environmental Scanner.
- Select the new object and in the Inspector window, add a new AudioSource component.
- Create a new folder called Audio in the Assets/ARCoreML path in the Project window.
- Open the Resources folder from the downloaded code folder and copy the tone-beep.wav file to the new Assets/ARCoreML/Audio folder you just created.
- Open up the Environmental Scanner object in the Inspector window and set the AudioSource properties, as shown in the following screenshot:
Setting the AudioSource properties in the Inspector
- With Environmental Scanner still selected, click on the Add Component button in the Inspector window. Add the Environmental Scanner script we wrote earlier.
- Open the Build Settings dialog and ensure that you add the current scene (Main) to the build. Ensure that you remove any other scenes from the build.
- Connect, build, and run. Move around the room. Now what happens when you get too close to objects? At what distance?
Great, so we have effectively made a backup or warning beeper to let you know when you are getting too close to an object. Obviously, we could have just as easily written a simple threshold test ourselves to test when min is getting too close. However, this simple example gives us a good basis for understanding how training works.