Skip to content
January 13, 2014 / CoffeeCoder

New Beginnings?

I have encountered some serious, serious issues with my current game, and how things are handled inside of it.

First, I’ve had some issues with the physics engine, and have done some research which shows the way I’m controlling the player isn’t exactly the best.  While this would be a small change to make, changing it would mean basically re-writing almost 200 lines of code, because of the way I’m storing the player’s information and stats.  I’m just using regular old public(!)* variables that I can set in the Inspector, but what I should do is separate that information from the control input script entirely, and store all of player info (score, lives, hp, mp, whatever else I may need) in what’s called a GameState Manager.

A GameState Manager is a very handy script, written in a Singleton pattern (meaning there’s only ever ONE instance of the object) in which I can do things like set the current game session’s information through a loaded save file,  save the current game state to a save file, set the current level, update the player’s lives, health, and whatever else I may need.  They’re pretty awesome things, and should be talked about more, because I’ve only learned of them through a couple of references people have posted on the TGC forums, and a reference in a lesson on GameInstitute.com.

They’re a way to centrally control specific parts of the game, and accessing parts of it through other scripts would be as easy as this:

if(enemyStrikesPlayer)
{    
    // Update Player's health
    GameManager.Instance.SetHP(-enemy.hitForce);
}

 

The GameManager is the GameObject created by the script at run time, Instance is the instance of that object, and SetHP() is a public function that one could use to then update the player’s health.  And that could be accessed through any script, on any object, just like that.  Cool, eh?

Sadly, I can’t really re-start my project just yet.  This week, I’m going to New Orleans, Louisiana with some friends from Wednesday until early Saturday morning – meaning that I’ll have to wait a few days to start, since I don’t have a laptop to program on.  I wouldn’t want to anyway, except maybe in the car.  This also then affects my deadline for NaGaCreMo, but that’s ok – the project is still alive, and as long as I can complete something for it by the end of January, then all will be well!

*This, as we all know, is very very bad practice, although in some cases this is the only way to do things in Unity (when you want to set variables from the Inspector, for example).

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: