21st January
written by admin

I want to go over a few of the systems that I’ve been working on for Adventure Amazon.

State Machine System

I am a huge fan of state machines, in my opinion they simplify development, speed up debugging, and force cleaner code.  I want to build a state machine system in Unity that is user friendly and powerful at the same time.  I’ve started exploring the ability to create editor windows.  Here is a quick prototype that I put together.

Add Events, eventually will auto generate code stubs.

Add Events, eventually will auto generate code stubs.

The idea here is to create a system that allows the user to graphically design their state machine full while even allowing state hierarchy’s ( 1 state deriving from another ).  This is pretty ambitious undertaking for this project, but since I’ve proven that the editor tools support this addition, I have started working on the actual system behind the scenes now.  Feedback is always appreciated, but right now the plan is to have an empty text window open that displays the current code, or can be modified so the user doesn’t have to dig through code to find the generated stubs.  Another idea is to make each state an individual class instance, but to be honest I don’t feel that is the best way since we need data to be shared between states.  Although with that implementation it would allow each state to have their own data, that is instanced to the state instead of the entity.

NGUI and Touch Input

With the use of NGUI it is very simple to turn a 3D object into a button with touch input.  I’ve hooked up touch input and some simple menu’s which so far is working flawlessly.  I’ve also setup a bunch of menu scripts for energy, life, main menu etc.  NGUI actually had a much larger learning curve than I was hoping for, but luckily there is lots of samples and tutorials that got me up to speed.

Turret System

The turret is really what is going to manage everything from picking targets to adding guns, mods, and upgrades.  The turret code will need to handle its own health as well as communication with the menu so it knows when something is removed or added and the appropriate things happen.  Currently I have a very early version of the Turret base up and running.

Here is an example of how I am adding Turrets currently, this is all communication that happens from the UI that is instanced when the Turret is selected.

public void AddTurret( int slot, TurretTypes turret ) {
FreeTurret( slot );
CurrentTurrets[slot] = Instantiate( turretPrefabs[(int)turret], turretNodes[slot].transform.position, turretNodes[slot].transform.rotation ) as GameObject;
CurrentTurrets[slot].transform.parent = turretNodes[slot].transform;
CurrentTurrets[slot].transform.localPosition.Set( 0.0f, 0.0f, 0.0f );
CurrentTurrets[slot].transform.localRotation.Set ( 0.0f, 0.0f, 0.0f, 0.0f );

SendTargetToAllTurrets( );

public TurretTypes FreeTurret( int slot ) {
TurretTypes destroyedType = TurretTypes.None;
if( CurrentTurrets[slot] != null )
destroyedType = CurrentTurrets[slot].GetComponentInChildren<TurretGun>( ).typeOfGun;
Destroy( CurrentTurrets[slot] );
return destroyedType;

The reason I return the destroyed type is so the value of the gun can be refunded if necessary.  I want the entire system as generic as possible so its very simple to add and remove parts without ever effect the code.  I have the same system setup for modifiers as well.

Here is an example of how I currently retrieve the fire rate modifier from all the mods on the turret.

//Retrieve all modifiers from this turret
public float GetFireRateModifier( )
float mult = 1.0f;
foreach( GameObject gObj in CurrentMods )
if( gObj == null )

Mod modComp = gObj.GetComponentInChildren<Mod>( );
if( modComp.modType == TurretModType.FireRate )
mult *= modComp.FireRate;

return mult;

Now here what I do is iterate through all the currently attached mods and pull the fire rate modifier that each object has.  Every mod has the same values it may not even be an improvement to the fire rate.  The goal will be to allow balancing of any direction once we get to that point.

All very easy stuff honestly, and if you made it this far, thank you very much for reading my update.  Until next time – Adam