UnityLearn – Beginner Programming – Creating a Character Stat System – Pt. 05 – Accessing Variables in Our System Part 2 (End of Course)

March 6, 2020

Beginner Programming

Creating a Character Stat System

Accessing Variables in Our System Part 2


Beginner Programming: Unity Game Dev Courses

Unity Learn Course – Beginner Programming

Accessing Variables in Our System Part 2

Leveling Up

They created a LevelUp method within the CharacterStats_SO scriptable object. This accesses the leveling array they created earlier and sets all of the max stat values to those designated in the array for that corresponding level (each level is its own individual array element holding an entire list of all the stats and what they should be set to at that level).

Configuring Your Systems

They added the CharacterStats script to the main Hero character. They created empty gameobjects within the Hero character gameobject hierarchy for the character inventory and the character weapon. They then applied this to the base prefab (to make sure it wasn’t only on a newly created variant of the prefab).

They created a method named SavecharacterData, which uses the EditorUtility.SetDirty method from within the UnityEditor namespace to mark this class itself (CharacterStats_SO) as dirty. This does something with letting the system know the data on this object is dirty and needs to be saved again.

They mention this is not a necessarily good practice because they have a script that is using UnityEditor within a gameobject. This would cause an issue for end users playing the game as it will not run if they do not have Unity installed, since it needs access to Unity files.

They reiterate that your game will NOT EVEN BUILD if you have a script with a UnityEditor reference inside your scene. This reinforces that UnityEditor scripts are useful for building tools for your development team and debugging, but it is not to be used for the game itself.

SUMMARY

  • Use new prefab editor in Unity 2019 versions to work with prefabs
  • The UnityEditor namespace can be very helpful for building tools and debugging, but it is NOT for use for actual gameplay as this will keep the project from building