Let's modify Character and Paladin to print out different debug logs using PrintStatsInfo:
- Change PrintStatsInfo in the Character class by adding the virtual keyword between public and void:
public virtual void PrintStatsInfo()
{
Debug.LogFormat("Hero: {0} - {1} EXP", name, exp);
}
- Declare the PrintStatsInfo method in the Paladin class using the override keyword:
- Add a debug log to print out the Paladin properties in whatever way you like:
public override void PrintStatsInfo()
{
Debug.LogFormat("Hail {0} - take up your {1}!", name,
weapon.name);
}
This might look like repeated code, which we already said is bad form, but this is a special case. What we've done by marking PrintStatsInfo as virtual in the Character class is to tell the compiler that this method can have many shapes according to the calling class. When we declared...