Skip to content

STEP 3A: Creating a Simple User Interface in AR

rsees5 edited this page Jun 4, 2018 · 4 revisions

In this step you will learn how to add objects to your AR scene, change their appearance, and associate them with code that can send commands to an Arduino.

  1. Create a folder in your Assets folder called MyScripts by right-clicking in the Assets window and selecting Create -> Folder. Import the scripts from this repository by dragging and dropping them into the window.

  2. Create materials to be associated with your game objects by right-clicking in the Assets window and selecting Create -> Material. Name your first material Red. Select the box with the eyedropper next to it under Main Maps and choose the color from the pop-up Color window. Repeat this step, making Green and Yellow materials as well.

  3. Add an object to your scene by selecting GameObject -> 3D Object -> Cube. The cube will appear in the hierarchy on the left side of the Unity window. Drag it into the ImageTarget to make it a child part (this will be noted by an indentation in the hierarchy list).

  4. Add one of your materials from your Assets folder to the cube by dragging and dropping it into the Inspector window. You can also adjust the size and position of the cube under Transform. For the first cube, let's add Red.

  5. Add scripts to your object by clicking the Add Component button in the Inspector Window and selecting Scripts. You should see a list of the code we added in step 1 of this section. Click on "Spinny" and notice that it's been added to the Inspector window. Repeat this process and add "Call Red." When you've finished, your Inspector window should look like this:

  6. Repeat steps 3-5 of this section to make green and yellow cubes, associating the "Call Green" and "Call Yellow" scripts instead of "Call Red" as appropriate. If you made several ImageTargets, feel free to spread the cubes out between them by dragging and dropping them in the Hierarchy. This will change which cubes appear depending on the image in your view at the time.

  7. Navigate to the myScripts folder in your Assets and open the "Sending" file. Note the COM port value in this line of code:
    public static SerialPort sp = new SerialPort("COM5", 9600, Parity.None, 8, StopBits.One);
    You may need to adjust this depending on what COM port your Arduino is using from Step 2 (or Step 2A).

  8. Press the play button at the top of the Unity window to see your project in action!