VR Tutorial

Basic Concept

The GameObject is the most important concept in Unity; these are the basic entities in a screen. They represent everything from characters to items, light, cameras, and even special effects. 

A GameObject by itself cannot do anything special and we as the developer have to give it properties. A GameObject functions as a container for Components which implement the functionality. Depending on the type of object that you would like to create, you can add different combinations of Components to implement the desired functionality.

Unity has several built in component types, for example in our project, in the Hierarchy window, we can find that our project created the Directional Light GameObject by default. This GameObject automatically has the Light component attached to it which you can view in the Inspector window on the right side of the editor. Additional components can be added with the Add Component button. 

 

Unity also offers the functionality to create your own scripts, allowing for a great deal of customizability. Scripts are written with the C# programming language, so when planning an application, it is also important to factor in whether custom scripting functionality will be needed. Programming as a skill is not easily taught, especially with a language such as C# which is not as popular in recent times, so it may be necessary to seek the help of a developer to implement custom functionality. Understanding basic programming concepts as well as the Unity API is crucial for creating custom scripts. Additional information about the Unity API can be found here: Scripting.

Reference Project

In our project, all of the Petri dishes containing the compounds needed to have custom functionality. We can see in the Inspector Window for our Copper Dish GameObject that there is a custom script called Dish.

 

Each compound petri dish GameObject also contains a component called the Box Collider which defines a box-shaped physical collision zone. This is used to detect collisions with other objects in the scene and interact with Unity's physics engine.

Let's break down a bit of how the Box Collider works:

  • Size: determines the dimensions of the box in the local space of the GameObject. It is a vector representing the extents of the box along its local x, y, and z axes
  • Center: sets the position of the center of the box collider relative to the GameObject's transform. It is also a vector in local space
  • IsTrigger: when this property is set to true, the collider now functions as a trigger collider. Trigger Colliders don't physically interact with other colliders but instead send messages when other colliders enter or exit the trigger zone

The IsTrigger functionality is selected such that our custom script that we wrote for our "rod" can detect when it comes into contact with a compound dish, remember the properties of said dish, and when it comes into contact with our bunsen burner flame, the appropriate flame color can be shown. The Inspector window for our Rod is shown below.

 

In the Rod's Inspector window, we see that that rod uses another component called Rigidbody. This component is used to give GameObjects physics behavior. Since the metal ions in the compound would be "on the rod", when the rod comes into contact with the flame, the new characteristic color of the flame should appear where the rod is in contact with the flame. Because of this we need to define some physics for how the flame will appear. We will continue to explain the Rigidbody component in the section titled Rigidbody and Transform.