Astrofighter.Net - Now suddenly loving C#
Today I redesigned the code for weapon handling in Astrofighter.Net and the game now supports very dynamic creation of weapons and weapon upgrades. Each weapon is configurable with tons of settings such as various sound effects, autofire, charge up for increased power, rounds per minute, and so forth. In all there are about 40 customizable settings for a weapon and for potential powerups / upgrades.
While rewriting, and documenting, my code it strikes me how much I'm starting to like C# and the intellisense autocompletion of all variable names and functions. Today I learned about the ability to use the {get; set;} feature to treat a variable as a property - quite nifty. What this means is that you simply define a variable like this:
This enables you to from other scripts access the variables directly:
The only downside is that you can't have these variables show up in the Unity inspector to assign them a default value which is a shame. There is a workaround for this in Unity but it requires a bit of code bloating so I simply don't use inspector configured values in this case.
I'm very happy with today's progress as it enables me an incredible level of control of my weapons and powerups. Should be able to create tons of cool upgrades that split bullets, enable homing missiles, alters velocity and force of projectiles, and so on.
While rewriting, and documenting, my code it strikes me how much I'm starting to like C# and the intellisense autocompletion of all variable names and functions. Today I learned about the ability to use the {get; set;} feature to treat a variable as a property - quite nifty. What this means is that you simply define a variable like this:
public float velocity { get; set; }
This enables you to from other scripts access the variables directly:
// this automatically uses set
remoteScript.velocity = 10;
// this automatically uses get
Debug.Log(remoteScript.velocity);
The only downside is that you can't have these variables show up in the Unity inspector to assign them a default value which is a shame. There is a workaround for this in Unity but it requires a bit of code bloating so I simply don't use inspector configured values in this case.
I'm very happy with today's progress as it enables me an incredible level of control of my weapons and powerups. Should be able to create tons of cool upgrades that split bullets, enable homing missiles, alters velocity and force of projectiles, and so on.
Comments
Post a Comment