Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Difference between case sensitive APIs

Discussion in 'Getting Started' started by skeleton-king, Mar 31, 2015.

  1. skeleton-king

    skeleton-king

    Joined:
    Nov 10, 2014
    Posts:
    63
    Whats difference between a Tranform and transform
    Similarly there is Gameobject and gameobject
     
  2. blizzy

    blizzy

    Joined:
    Apr 27, 2014
    Posts:
    775
    Transform is a class, while transform is most likely a member of your MonoBehaviour subclass. Same with GameObject.
     
  3. Effervescent

    Effervescent

    Joined:
    Mar 7, 2015
    Posts:
    31
    I hope I'm getting the terminologies right here. xD The capitalised examples you gave (or what I assume you attempted to give - GameObject is different to Gameobject and I assume you are talking about the former) are classes whereas the non-capitalised ones are variables.

    Note that gameobject is also different to gameObject, as the latter is reserved by Unity as the variable that refers to the GameObject your script is attached to, as such:
    • GameObject - class
    • gameObject - variable reserved by Unity
    • Gameobject - user-defined variable
    • gameobject - user-defined variable

    In the case of Transform/transform:
    • Transform - class
    • transform - variable reserved by Unity that refers to the transform component of the GameObject the script is attached to


    EDIT: waaaaah, blizzy ninja'd me. xD
     
  4. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Unity convention is:
    • classes and methods in PascalCase.
    • properties and fields in camalCase.
    So in general the PascalCase version is referring to the class itself. The camelCase version is referring to an instance of the class.

    This is just convention. There is nothing aside from posts on the forum actually enforcing this. Different languages and communities use different conventions.
     
  5. skeleton-king

    skeleton-king

    Joined:
    Nov 10, 2014
    Posts:
    63
    So what does this code means
    what does Tranform and tranform refers to in code below

    void Example() {
    foreach (Transform child in transform) {
    child.position += Vector3.up * 10.0F;
    }
     
  6. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,769
    A foreach iterates over an array or collection of objects. Each pass of the loop it takes the next available entry in the collection and assigns it to the variable name specified in parenthesis.

    In this case the loop is taking the next available child of the GameObject with the script, grabbing its transform property, and assigning it to a varaible called child of type Transform.

    Code (csharp):
    1. void Example() {
    2.    foreach (Transform child in transform) {
    3.       child.position += Vector3.up * 10.0F;
    4.    }
    5. }
    By the way, if you use code tags the forum software will automatically create forum links to the API docs. Try clicking on "Transform" in the above code. Though it doesn't do all of them, it does get most. ;)
     
    Last edited: Mar 31, 2015