Introduction to Unity Scripting

Gluing components

The Unity engine provides several components that allow developers to create games seamlessly, just by dragging/dropping and configuring these said components. They cover a broad range of domains such as graphics (Lights, Cameras, Materials, VFX, etc.), physics (Rigidbody, Colliders, etc.), UI, audio, and animation. However, scripting is what glues all of these components together to build a production-ready project.

Unity without scripting

Most in-game interactions can be dealt with via the use of components, such as making a ball bounce on a platform. To do this, simply create a new project and follow the steps below:

  1. Click “GameObject > 3D Object > Cube” to add a cube and extrapolate it. This will serve as the platform.

  2. Click “GameObject > 3D Object > Sphere” to add a sphere that will serve as a ball, and use the Move tool in the “Scene” view to position it above the ground.

  3. Right-click the “Project” window and select “Physic Material.” Set the “Bounciness” of this material to 1 and drag it onto both the platform and the ball in the “Scene” view.

  4. Finally, add a “Rigidbody” to both the platform and the ball from the “Inspector” window. However, turn off the “Gravity” option and turn on the “Is Kinematic” option for the platform.

Note that we used a cube to create the platform instead of a plane GameObject for the following reasons:

  • A plane comes equipped with a mesh collider, whereas a cube comes with a Box Collider; therefore, as we know from the Physics lessons, primitive colliders are performance efficient compared to mesh colliders.

  • Secondly, a plane’s “Scale” property for the y-axis doesn’t shrink or expand. Therefore, its thickness can’t be changed, unlike a cube’s.

In just four steps, you’ll have a scene ready, as shown below:

Get hands-on with 1200+ tech skills courses.