top of page

What is Unity? Part 2!

Updated: Feb 25, 2021

Written By: Saniya Kalamkar

Manipulating Game Objects


Transform Components:

  • The Transform component allows you to manipulate a GameObject’s position, rotation, and scale. Every GameObject has a transform property.

  • Position determines the GameObject’s position of the transform in X, Y, Z coordinates. It simply moves the gameObject to another place.

  • Rotation determines the GameObject’s rotation of the transform in X, Y, Z axes and is measured in degrees

  • Scale determines the GameObject’s scale of the transform in X, Y, Z axes

  • Coding gameObject.transform.Translate(newVector(1, 0, 0));

Shortcuts with Transformations:

  • Pressing “W” allows you to edit the translate component

  • Pressing “E” allows you to edit the rotate component

  • Pressing “R” allows you to edit the scale component

Parenting:

  • Parenting a GameObject means that there is a Child GameObject attached to it. This means that if you change any transform components of the Parent GameObject, the Child GameObject will follow. For example, moving the Parent GameObject to the left will mean the Child GameObject will go to the left automatically.

  • Parenting can be useful when you have something made up of multiple GameObjects. For example, in a car, when the body moves, you would assume the wheels would follow as well. So the wheels would be parented to the body of the car.

  • Child GameObject can also have children of their own. The levels of these GameObjects create a Hierarchy. The only GameObject that has no parents is known as the root.

  • You create a Parent GameObject by dragging a GameObject onto another GameObject in the Hierarchy view. For example, if you have a cube GameObject and a cylinder GameObject and want to Parent the cylinder to the cube, you would drag the cylinder to the cube.

Components:

Remember, GameObjects are just containers, so we have to attach components that determine the behavior of the GameObject. You can view GameObject’s components by clicking on it and looking at the Inspector. You can change a component by scripting. There are built-in components in Unity, such as the light, camera, rigidbody, box collider, among others. We will go more into depth on each component in the next article.


Scripting:

Sometimes, Unity’s built in components are not enough for what you want to achieve. Adding scripts to GameObjects allows you to add your own components. Unity allows you to use C# to code your scripts.

Creating Script File:

  • You create a script file by clicking Assets > Create> C# Script. You then enter the name of the file which you should do immediately.

What does a Script file look like?

  • Unity uses Visual Studios by default, so make sure you have that installed. Or you can select whichever editor you prefer.

  • The Script file looks like this:

using UnityEngine;

using System.Collections;


public class NameofFile: MonoBehaviour {


void Start () {

}

void Update () {

}

}

Functions of Monobehaviour Class:

The components inherit from the MonoBehavior Class.

  • void Start()

    • This is called before gameplay begins. Initialization code is put in here.

  • void Update()

    • Is called every frame. This is where most user input will go and it updates properties of GameObjects. Movement or or triggering actions are put in this area.

50 views0 comments

Recent Posts

See All
bottom of page