Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
GameObject in Unity | Write your First Script
Unity for Beginners
course content

Conteúdo do Curso

Unity for Beginners

Unity for Beginners

1. Unity Introduction
2. Write your First Script
3. Unity Physics
4. Unity UI and Sounds
5. Polishing and Export your Game

bookGameObject in Unity

A GameObject is like a container for everything you see and interact with in your Unity game. It can be anything from a character, a tree, a weapon, or even a light source. Think of it as a building block for your game world.

Every GameObject can have different components attached to it, which define its behavior and appearance. For example, you can add a "Sprite Renderer" component to display an image or a "Collider" component to detect collisions with other objects.

In simple terms, a GameObject is like a Lego brick, and components are like the different pieces you attach to it to make it look and behave the way you want in your game.

This is a GameObject that have as a name “Circle” and have two components the Transform and the sprite renderer.

Controle GameObjects with script

In the script when we write gameObject.

We refer to the game object to which this script is attached. You can find more about all the proprieties that the gameobject class have in this link: GameObject

Parent/Child relationship:

Parent GameObject: This is like the main container or the boss. It can hold other GameObjects, called child GameObjects. The parent GameObject can have its own components and properties.

Child GameObject: These are the GameObjects that are nested under a parent GameObject. They inherit certain properties and behaviors from their parent. For example, if you move or rotate the parent GameObject, all of its child GameObjects will move or rotate along with it.

Think of it like a family tree: the parent GameObject is like a parent, and the child GameObjects are like its children. If you move the parent, all its children move with it, but if you move a child, it doesn't affect the parent or other children at the same level. This parent-child relationship is handy for organizing your game objects, making it easier to manage and control them, especially when you have complex scenes with multiple objects.

Here's a step-by-step guide on how to make one GameObject a parent of another in Unity:

  • Click on the GameObject you want as the child;
  • Drag it onto the GameObject you want as the parent;
  • Release the mouse button;
  • Check the Hierarchy to confirm the parent-child relationship.

As you can see in the Hierarchy we have 3 object Main camera, GameObject and Parent. There is an arrow next the Main camera and GameObject that means that these objects have children if we click on that arrow, we will be able to see the children.

What’s next:

In our upcoming video, we will discuss the transform component.

1. What is the purpose of parenting GameObjects in Unity?
2. In Unity, can a GameObject have more than one parent at the same time?
3. What is the default parent of a GameObject when it is created in Unity?
What is the purpose of parenting GameObjects in Unity?

What is the purpose of parenting GameObjects in Unity?

Selecione a resposta correta

In Unity, can a GameObject have more than one parent at the same time?

In Unity, can a GameObject have more than one parent at the same time?

Selecione a resposta correta

What is the default parent of a GameObject when it is created in Unity?

What is the default parent of a GameObject when it is created in Unity?

Selecione a resposta correta

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 2. Capítulo 3
some-alt