Game Mechanics

One item I came across recently was when you should create your stunning graphics for your game and when you should work on the mechanics of your game. The term ‘game’ here is meaning any project your are creating using Unity or any other game engine. It doesn’t necessarily have to be a game it can be an interactive website or architectural walk through. The answer of course is game mechanics first, the art and object can be added later. While you are creating the game mechanics (e.g. scripts) your game object or assets can be anything (cube or sphere etc.) that can represent the physical size/area the actual objects will be. In other words you can make a cube move just as easy as a animated character or camera.

Working through some new videos I found and converting all the scripting to versions that will work with Unity 5. Today I had to set one aside as it just was not working. It all boiled down to the original author created a public Transform variable ‘player’ and then drag and drop the player game object into the inspector.

I wanted to create a private reference variable and assign the value in the awake function, no drag and drop leaving the inspector less cluttered. When I did this I created a private GameObject variable ‘player’ and a private Vector3 variable ‘playerPos’. I would then assign their values in the Awake() function by finding with tag then a GetComponet for the transform.position Vector3. The problem I had was nothing would work when I tried to use the playerPos while I was moving around.

Well duh! When I got home I realize I initialized the playerPos at awake and it did not matter how much I moved around the value of that variable would not change.. 🙂 .

Solution: private Transform variable ‘player’, assign in awake using ‘player = GameObject.FindGameObjectWithTag(“Player”).transform’. When referencing my players position during play just use player.position. Kept the inspector less cluttered and worked like a champ.