Understand Custom Class.
Objective: Understand Custom class.
Why use custom class ,custom class gives us ability to create modular program and it make easy process of scale the program or debugging.
Before go into custom class lets see this example, In order for player to have different weapons we create all code for different weapons in player script. But this will make player script very big and it will be hard to debug and scale the program.
Lets begin here ,to create a modular program we need to take advantage of custom class.
Get Suleiman Abdullah’s stories in your inbox
Join Medium for free to get updates from this writer.
A custom class is the type of class which do not Inherit MonoBehavior, I will create it and call it WeaponStats. Note Remove the MonoBehavior in the WeaponStats script.
I want to have a homing missile ,so I will create a script for homing missile behavior.
Assume we already have player script and powerup script ,the powerup script is responsible to give player different type of power up.
Go to the Custom class ,provide a state of your weapons for mine it has name ,fireRate and ammoCount.
When we use custom class it give us an advantage of using cunstructor,a cunstructor used to initialize things of the custom class .We define a cunstructor by public keyword follow by custom class name, double quote end with curly bracket.We use this to Initialize our stats in dynamic way,so whenever we want to make another weapon we can define the stats without modify the base class.
If we get powerup ,we create an Instance of WeaponStatus and called a name of Weapon, then give the attribute of that weapons. So we can use weaponStats to define the speed of Weapons, mass, damage Amount, this help build modular app without clutter everything in one class.
See you in the next one










