Wednesday, April 13, 2016

Redo of the Doors #gamedev

Experience has taught me that everything can be improved. This absolutely includes my code.

The doors I wrote many moons ago have worked very well these last 11 months or so. However I have learnt so much more about using Unity, as well as improving my own C# coding skills along the way. Now the Door control code has also got out of hand as I now have like 40 doors in the game, and not the several I had written the routines to control.

In short.. the door code is being inefficient and cumbersome, it was also not very Editor friendly. In fact the name of the Object was being string compared for me to know which door ID to use. Ouch!

Today was a time to refactor this code. Initially I was going to make each door a World Object, and then they would all go into my World Array. This has a number of benefits, but I realized before this update that this would add 40 Items to the World Array. An array that is cumbersome within Unity as choosing one of these Enums takes me time to scroll through the 110 plus that is already in there. I do think that Unity could do a better job allowing me to select an Element within this fairly Large array.

So instead of this answer I simply made a new script that only contains a Public variable of the Enum type that controls my Doors. This means that I can select which door this object is, and not have to rely on typing the name correctly, or comparing to some string I type within the game code. A Huge improvement, and I will only end up with more doors, so this is a good change for the future as well. Making my life easier and therefore saving more time in the future. Not bad for 20 minutes work (I had to go through every scene and fix up the Doors).

Da Voodoochief

No comments:

Post a Comment