My character creation order is: Select Race, Select Class, Assign Bonus Stat Points, Customize and Name the character.

Because I am using Unity's UI components I am using scripts attached to empty objects (eg. _RaceManager, _ClassManager) that handle which button is pressed and select the actual race or class.

However a look on the inspector shows stat values as 0. So I must be doing something wrong!

MY QUESTION: How would my Playing Character (Player) get the selected values depending on race and class?

Here is an example of my code (actual code is too big to post):

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.EventSystems;

public class Class_GOnClick : MonoBehaviour {
    public GameObject Barbarian, Knight, Paladin, Assassin, Scout, Shadow, Elementalist, Druid, Summoner, Priest, Hunter, Next, Previous, descRect, ClassPanel, RacePanel, RaceManager;
    StageIDs sID = new StageIDs(); //0 - ERROR, 1 - RACE, 2 - CLASS, 3 - STATS, 4 - CUSTOMIZATION
    public static BaseClass classSelection;
    public void Start()
        sID.id = 2;
        Barbarian.GetComponent<Button>().onClick.AddListener(() => { isBarbarian(); });
        Next.GetComponent<Button>().onClick.AddListener(() => { _Next(); });
        Previous.GetComponent<Button>().onClick.AddListener(() => { _Previous(); });
        descRect = GameObject.Find("DescriptionText");
        descRect.GetComponent<Text>().text = "";

    public void isBarbarian()
        SaveInformation _Info = new SaveInformation();
        classSelection = new BarbarianClass();
        descRect.GetComponent<Text>().text = classSelection.CharacterClassDesc;
        _Info.Constitution += classSelection.Constitution;
        _Info.Strength += classSelection.Strength;
        _Info.Intelligence += classSelection.Intelligence;
        _Info.Dexterity += classSelection.Dexterity;
        _Info.Charisma += classSelection.Charisma;
        _Info.Wisdom += classSelection.Wisdom;
        _Info.Willpower += classSelection.Willpower;
        _Info.Luck += classSelection.Luck;
        _Info.Perception += classSelection.Perception;
        _Info.MaxPhResist += classSelection.MaxpResist;
        _Info.MaxMaResist += classSelection.MaxmResist;  
        _Info.MaxSpeed += classSelection.MaxSpeed;

public void _Next()
    public void _Previous()

As requested, the Barbarian Class:

using UnityEngine;
using System.Collections;

public class BarbarianClass : BaseClass {

    public BarbarianClass(){
        CharacterClassName = "Barbarian";
        CharacterClassDesc = "The Barbarian is a breed of Fighter focused more on damage than defense. Often characterized by wearing less armor, being less civilized, and being able to fly into a berserker rage that increases damage output or allow them to do more damage based on how hurt they are.";
        CharacterClassOrigin = "Fighter";

        //Base Stats

        Constitution = 5;
        Strength = 10;
        Intelligence = 5;
        Dexterity = 5;
        Charisma = 3;
        Wisdom = 3;
        Willpower = 3;
        Luck = 3;
        Perception = 5;
        //CurHp = ;
        //MaxHp = ;
        //CurpResist = MaxpResist;
        MaxpResist = 5;
        //CurmResist = MaxmResist;
        MaxmResist = 1;
        //CurSpeed = MaxSpeed;
        MaxSpeed = 5;


  • \$\begingroup\$ Show the BarbarianClass \$\endgroup\$ – Savlon Jul 13 '15 at 1:13
  • \$\begingroup\$ @Savlon Done. :) \$\endgroup\$ – Valamorde Jul 13 '15 at 3:11

Move _info into class-scope. In your code it is a local variable which is destroyed when isBarbarian returns

public SaveInformation _Info; 
public void Start()
public void isBarbarian()
   _Info = new SaveInformation();

When you make changes to your .NET assemblies, Unity copies the existing data to the un-managed side, reloads the new assemblies, then copies the data back. Classes you create are not serializable, by default, so Unity will not be able to "see" them. This is also required since this SaveInformation is probably going to be.... saved (serialized to disk). This is done through the [System.Serializable] class-level attribute and the [NonSerialized]/[SerializeField] field-level attributes.

[System.Serializable] //This allows Unity to "see"
class SaveInformation
   public float PublicFloat1; //Serialized

   public float PublicFloat2; //Not serialized

   private float PrivateFloat1; //Not serialized

   private float PrivateFloat2; //Serialized
|improve this answer|||||
  • \$\begingroup\$ This answer would be far more helpful when you would not just post what needs to be changed but also explain why. \$\endgroup\$ – Philipp Apr 17 '16 at 12:15
  • \$\begingroup\$ @Philipp, I fixed it right? Thank you. \$\endgroup\$ – Jon Apr 17 '16 at 12:34
  • \$\begingroup\$ You really shouldn't place your explanations as comments in your sourcecode. It makes it hard to separate from the code. I took the freedom to edit your answer the way I would have done it (feel free to revert when you think I changed it too much). \$\endgroup\$ – Philipp Apr 17 '16 at 12:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.