DK2D Log# 11 Making A Data Class For Player Stats
For creating easier save files later, I will need to create a Data Class, this can contain many variables in one container basically. To…
DK2D Log# 11 Making A Data Class For Player Stats
For creating easier save files later, I will need to create a Data Class, this can contain many variables in one container basically. To start with, I can create the player’s stats in a data class. This class can hold all the stats the player will have that will be saved when the game is saved. To create a data class, I just need to remove the MonoBehaviour from a C# class when I create it and also add System.Serializable to the class, this way it can be viewed in the inspector window in Unity.

Next I took some time to think of all the basic stats the player will manage in the game and which ones will be saved. First I added a string, which would hold the Player’s Chosen Name, then a series of floats and ints that would hold health, gold, exp stats, and more I will get into later when I develop each of these sections.

Now that I have this data class, to access all of these stats on the player, I can add another script called PlayerStats and add PlayerStatsData as a public variable.

I will get into using this for saving later, but for now, I can go back into the Unity Editor and look at the script to set some default starting points for some of the stats.

메타데이터
- post_id
- 8802b85affc9
- slug
- dk2d-log-11-making-a-data-class-for-player-stats-8802b85affc9
- url
- https://medium.com/@eclipsek24/dk2d-log-11-making-a-data-class-for-player-stats-8802b85affc9
- canonical_url
- https://medium.com/@eclipsek24/dk2d-log-11-making-a-data-class-for-player-stats-8802b85affc9
- author_url
- https://medium.com/@eclipsek24
- status
- ok
- fetched_at
- 2026-06-26 21:52:29