- Augmented Reality for Developers
- Jonathan Linowes Krystian Babilinski
- 407字
- 2025-04-04 18:11:44
Adding a cube
Now we'll add an object to the Scene, just a simple cube:
- In the Hierarchy, select the GibraltarTarget, right-click 3D Object | Cube (or, from the Main Menu, choose GameObject | 3D Object | Cube and make it the child of the target object).
This will create a unit-sized cube, one meter on all sides. Obviously, that's much too big for our target, which is closer to 0.2 units sized. So, over in the Inspector, in the Transform component, modify the Scale to something more manageable right now, such as (0.05, 0.05, 0.05).
You may need to adjust your view in the Scene view panel, but when you do, you can see that our target object appears along with the cube, as shown here:

It's somewhat awkward to have the target standing vertically, when, in real life you might expect it to be lying horizontally (that is, flat):
- Select Root in the Hierarchy and, in Inspector, change its Rotation-X to 90 degrees.
- We can also move the cube so that it's positioned in the center of the target, more or less.
After adjusting the position of the cube in my scene to Position (0.12, 0.076, -0.037), it looks like this:

One last thing: double check that the objects under ARRoot are all on the AR background 2 layer.
- If you select ARRoot and, in Inspector, set its layer again, Unity will prompt you to change all of its children's layers as well. Do it.
Now we're ready to see it work. Press Play again in the Unity toolbar. Point your webcam at the printed Gibraltar image. Our cube should appear. Woot again!!!
The following image shows me pointing my webcam at the target Gibraltar image, with Unity running the scene on the monitor in the background. In the Game panel, you can see the video feed from the webcam, with the cube added to it, in all its augmented reality awesomeness!
