Time for action – Making a custom weapon
The best way to learn about inheritance is to see it in action, and the most basic way to see it is through a game's weapons. They're easy to modify and are a good starting point for learning about the UDK's classes.
Create a new
.uc
file in ourAwesomeGame
/Classes
folder and call itAwesomeGun.uc
. Write the following code in it:class AwesomeGun extends UTWeap_RocketLauncher_Content; defaultproperties { FireInterval(0)=0.1 ShotCost(0)=0 }
Compile our class. Now here's where we would ask, "How did it compile? I didn't declare any variables, but we're putting some in our default properties!" This is how inheritance works. We already saw the
ShotCost
variable inUTWeapon
on line 27:/** Holds the amount of ammo used for a given shot */ var array<int> ShotCost;
If we look higher up in the class tree at Weapon, we can see
FireInterval
on line 44 (as of the October 2011 build):/** Holds the amount of time a single shot takes */ var() ...