- Home /
Difference between gameObject and GameObject and a scene item named "GameObject" and this in context of Unity grammar
This is related to another thread, except this
was not compared there, nor Unity's usage of capitalization and inclusion of spaces-in-variable-names-in-editor,* so for clarity, please explain here!
(Community wiki)
Some further questions:
Why are variables called cameraOffset labeled as "Camera Offset" in inspector? Why the inclusion of a space?
Why is it that when you have a Mesh.js in asset, it'd stop the whole show? Is there a list of "forbidden file names"?
Just like GUI.js So I'd say their are some names you can't use.
Answer by Mike 3 · Dec 27, 2010 at 04:42 AM
- Why are variables called cameraOffset labeled as "Camera Offset" in inspector? Why the inclusion of a space?
This is because the GUI has a function to make variable names readable - it'll turn camelCaseName into Readable Language Name. It splits every time it finds a capital letter in the camel case version, adding a space there.
- Why is it that when you have a Mesh.js in asset, it'd stop the whole show? Is there a list of "forbidden file names"?
Any time you overload the name of a unity class, it'll go wonky. Check the list of classes used in the runtime api here: http://unity3d.com/support/documentation/ScriptReference/20_class_hierarchy.html
when you reference a script -- say "BobJones.js" in another object, do you call it as GetComponent(BobJones) or GetComponent("Bob Jones") - and what about the variables?
Answer by Jesse Anders · Dec 27, 2010 at 04:48 AM
The difference between 'GameObject' and 'gameObject' is as described in the other thread (although I'm not sure about the GetComponent() part - I've never seen that before, and I haven't tried it myself).
For a game object to be named 'GameObject' is completely incidental and has nothing to do with the class named 'GameObject'. It would be like if you had a cat and named it 'cat'. Yes, the cat's name also happens to describe what it is, but that's incidental; the cat could just as well be named 'Mittens' or 'Fluffy'.
Regarding cameraOffset vs. Camera Offset, that's just a (sort of confusing) bit of 'humanization' that Unity does for you. The variable is, indeed, named cameraOffset, but Unity 'humanizes' variable names for display in the inspector. This means that the names of the variables as seen in the inspector are often different than the variables' actual names in the source code. (Among other things, a space is not a valid character for symbols such as variable and function names, etc.)
Not sure about Mesh.js, but I'd guess it has something to do with the fact that there's already a class called Mesh (maybe). [Edit: See Mike's answer above.]
Added a reply on the other question about the GameObject thing, it's not valid
Any chance one of the genius/guru's of UnityScript could layout all the relationships and ways to call objects and components attached to objects in a manner that makes easy sense to a pleb? The pleb being me. And from the looks of things, a few others...
@dissidently: It may not answer every question you have, but I'd recommend starting here: http://unity3d.com/support/documentation/ScriptReference/index.Accessing_Other_Game_Objects.html.