UnityLearn – Beginner Programming – Creating a Character Stat System – Pt. 02 – Damage, Leveling Up, and Death

February 12, 2020

Beginner Programming: Unity Game Dev Courses

Creating a Character Stat System

Damage, Leveling Up and Death


Beginner Programming: Unity Game Dev Courses

Unity Learn Course – Beginner Programming

Damage, Leveling Up and Death

Encapsulation and Item Pickups

They cover encapsulation again just to explain why they use different access modifiers for different fields and methods within the scriptable objects they are creating to deal with the character’s stats and items.

Stat Increasers

They covered methods that increased the stats of the character. They were pretty basic, where they added values to specific stats and checked if the value would go over the max value to set it directly to max if that was the case.

Stat Reducers

This was very similar to Stat Increasers methods, but with subtraction and checked if the value would go below 0. This made me realize there’s a better way to do this where you check if a value would go below 0 BEFORE actually performing the operation, and then set it to 0 if that is the case. This prevents cases where you make a value negative for any step in the code which could result in weird problems down the road.

Leveling Up and Dying

They took an interesting approach to the level up process. They created a new class within the CharacterStat_SO scriptable object named CharLevelUps. These CharLevelUps objects just contained a bunch of int and float fields for different stats, and would be the amount to increase those base stats upon attaining the next level.

They then created an array of these CharLevelUps objects in the CharacterStat_SO class. You could then see this array in the editor and set a number of them to create (in this case, it would dictate the max level of the player). The designer could then set the individual values for each of these stats for each CharLevelUps object in the array to tell the system how much to increase each stat specifically upon attaining that specific level.

SUMMARY

  • Control your encapsulation when dealing with scriptable objects
  • Make sure to have checks for max and min values when modifying stats
  • Creating new classes that just hold a bunch of fields and then creating an array of those classes can be a very nice modfiable tool for a designer to work with