Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

What is the difference between GameObject and gameObject

Discussion in 'Scripting' started by Wasiim, May 11, 2015.

Thread Status:
Not open for further replies.
  1. Wasiim

    Wasiim

    Joined:
    May 2, 2015
    Posts:
    228
    When is each case used and yes i understand gameObject is an instance.
     
  2. Deleted User

    Deleted User

    Guest

    Well 'gameObject' usually refers to the gameObject variable inside a MonoBehaviour.
    GameObject would usually be the type of the object.
     
  3. Stardog

    Stardog

    Joined:
    Jun 28, 2010
    Posts:
    1,887
    gameObject is a shortcut word that gives you the GameObject this script is attached to. Like "transform" compared to "Transform".

    GameObject is a type like float/string/bool/Transform/etc.
     
  4. 5vStudios

    5vStudios

    Joined:
    May 9, 2015
    Posts:
    106
    gameObject refers to the GameObject that the current script is attached to
    whereas
    GameObject refers to a object type / entity

    with that being said:
    gameObject would be used when you want to reference the GameObject that the script is attached to for example:
    Code (CSharp):
    1. gameObject.GetComponent<Transform>();
    The code above will reference the Transform component that is on the GameObject that the script is attached to
    where as
    GameObject would be used in an instance where you want to create a variable etc
    for example:
    Code (CSharp):
    1. GameObject myPlayer;
    the code above simply create a varible called 'myPlayer'
     
    Last edited: May 12, 2015
  5. DarthKarLox

    DarthKarLox

    Joined:
    Jan 21, 2021
    Posts:
    1
    Thanks, very nicely explained
     
  6. SirhotBay

    SirhotBay

    Joined:
    Feb 3, 2021
    Posts:
    12
    Very great explanation. thank you.
     
  7. musharafhassan67

    musharafhassan67

    Joined:
    Feb 18, 2022
    Posts:
    2
    ok
     
  8. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,525
    Please, don't necro a thread to say "ok". If it helped then please just hit the "Like" button. It won't then get surfaced for everyone.

    Thanks.
     
Thread Status:
Not open for further replies.