When to start uppercase or lowercase

Hi,
Is there some logic in the use of uppercase and lowercase in the script syntax?
I think I learned it like this:

  • methods start with capitals, variables start with lowercase.
  • And when refering to an instance (gameObject), you start with lowercase, refering to a class start uppercase (GameObject)
  • Please correct me if I’m wrong.

But why is in this line below, the L (Length) is capital but the p (position) is lowercase. They are both variables, right?

Instantiate(prefabs[Random.Range(0,prefabs._Length)], newTransform.p_osition)

It’s so annoying to do this wrong all the time…

Why not to listen the creators

Note though, .Net capitalize property names, Unity does not. That is why Length is capitalized, and position is not.

1 Like

This.

Properties are half way between methods and variables. Unity and Unity developers have a habit of treating them more like variables. .NET and .NET developers tend to treat them more like methods.

Unity land is generally less strict on pure encapsulation principles then .NET land. This is because Unity’s serialisation system does not play very well with properties and encapsulated data. As a side effect of this it often makes sense to retractor a variable to a property, or vice versa. Having the names identical means you don’t have to change the public API.

On the other hand .NET land encourages strict encapsulation. To the point where there are no public variables, everything is accessed through a property. Thus there is never any need to change the public API.

2 Likes

by the way, i 'm using javascript. I couldn’t find the answer to my question on the page that L-tyrosyne sugested. Still confused…

You’re using unityscript, and there’s no real naming standards defined for it.

You could apply the C# standards to it, which is what that article covers.

If you want to understand the standards laid out throughout the unity API… that was covered by @Kiwasi . Unity doesn’t capitalize it’s properties, and instead follows a more ‘javascript’ standard (javascript does have a standard, unityscript does not), for the reasons BoredMormon stated.

That all together is the answer.