TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

Unity GameObjects

Unity GameObjects with Introduction, Installing, GameObject, First Unity Project, Unity 2D, Sprite Unity, Loops, If Statement, Data Types, Swith Statements, Unity UI, Unity Asset Store etc.

<< Back to UNITY

Unity GameObjects

The GameObject is the most important thing in the Unity Editor. Every object in your game is a GameObject. This means that everything thinks of to be in your game has to be a GameObject. However, a GameObject can't do anything on its own; you have to give it properties before it can become a character, an environment, or a special effect.

A GameObject is a container; we have to add pieces to the GameObject container to make it into a character, a tree, a light, a sound, or whatever else you would like it to be. Each piece is called a component.

Depending on what kind of object you wish to create, you add different combinations of components to a GameObject. You can compare a GameObject with an empty pan and components with different ingredients that make up your recipe of gameplay. Unity has many different in-built component types, and you can also make your own components using the Unity Scripting API.

Three important points to remember:

  1. GameObjects can contain other GameObjects. This behavior allows the organizing and parenting of GameObjects that are related to each other. More importantly, changes to parent GameObjects may affect their children ? more on this in just a moment.
  2. Models are converted into GameObjects. Unity creates GameObjects for the various pieces of your model that you can alter like any other GameObject.
  3. Everything contained in the Hierarchy is a GameObject. Even things such as lights and cameras are GameObjects. If it is in the Hierarchy, it is a GameObject that's subject to your command.

Creating and Destroying GameObjects

Some games handle a number of objects in the scene, but we can also create and remove the treasures, characters, and other objects during gameplay.

In Unity, we can create a GameObject using the Instantiate function, which makes a new copy of an existing object:

public GameObject enemy;

void Start() {
    for (int i = 0; i < 6; i++) {
        Instantiate(enemy);
    }
}

Unity can also provide a Destroy function that is used to destroy an object after the frame update has finished or optionally after a short time delay:

void OnCollisionEnter(Collision otherObj) {
    if (otherObj.gameObject.tag == "Missile") {
        Destroy(gameObject,.5f);
    }
}

Note that the Destroy function is also used to destroy individual components without affecting the GameObject itself. A common mistake is to write something like:

Destroy(this);

Next TopicUnity Components




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf