Question About Naming Conventions

What sort of naming-conventions are you guys using to help keep your variable names clear. For example, I’m often holding local references for the following common types of objects:

  • Transforms
  • Script Components
  • GameObjects

And those can get confusing. For example, let’s say I instantiate a player. I now have a variable for the player’s gameObject, transform, and the script component. Without a good naming convention, a variable like “player” really doesn’t tell you much. If I come back and look at that variable in a week’s time, I won’t know if it’s the player’s transform, gameobject, or script that’s being referred to. Sure, there’s typecasting, but I find it’s not enough.

Has anyone developed a good naming convention for this? Like:

player_s = script
player_o = object
player_t = transform

I’m just wondering about best coding practices, cause as my project balloons, I find myself relying on them more and more to keep things sane.

I use “this” + component name for components of the game object that the script is attached to.

For example:

private Transform thisTransform;
thisTransform = transform;

I use script name + “Script” for scripts.

For example:

private PlayerMovement playerMovementScript;
playerMovementScript = gameObject.GetComponent();

I use “enum” + enum name for enum-type variables.

For example:

private ENUM_Axis enumAxis;
enumAxis = ENUM_Axis.XAxis;

I usually just do

playerTransform : Transform
playerScript : Script
playerObject : GameObject

I don’t like abbreviations; they’re too confusing for me. The last one is debatable, since there’s a difference between Object and GameObject, but I almost never use Object, so I always know it means GameObject.

–Eric