i was trying to go through the other threads, but it seems like my code and theirs pretty much match up.
i’m trying to display the values of the stats next to the names of the stats, however i only get the first stat with no value next to it, and a constant console error of “Object ref not set to an instance”
here’s the code:
using UnityEngine;
using System.Collections;
using System; //used for the Enum class
public class CharacterGenerator : MonoBehaviour
{
private PlayerCharacter _toon;
// Use this for initialization
void Start ()
{
_toon = new PlayerCharacter();
_toon.Awake();
}
// Update is called once per frame
void Update ()
{
}
void OnGUI()
{
GUI.Label(new Rect(10, 10, 50, 25), "Name:");
_toon.Name = GUI.TextArea(new Rect(65, 10, 100, 25), _toon.Name);
for(int cnt = 0; cnt < Enum.GetValues(typeof(AttributeName)).Length; cnt++)
{
GUI.Label(new Rect(10, 40 + (cnt * 25), 100, 25), ((AttributeName)cnt).ToString());
GUI.Label(new Rect(115, 40 + (cnt * 25), 30, 25), _toon.GetPrimaryAttribute(cnt).AdjustedBaseValue.ToString());
}
}
}
any help is appreciated! Thanks!
think this might be another source of the problem:
using UnityEngine;
using System.Collections;
using System; //added to access the enum class
public class BaseCharacter : MonoBehaviour
{
private string _name;
private int _level;
private uint _freeXP;
private Attribute[] _primaryAttribute;
private Vital[] _vital;
private Skill[] _skill;
public void Awake()
{
_name = string.Empty;
_level = 0;
_freeXP = 0;
_primaryAttribute = new Attribute[Enum.GetValues(typeof(AttributeName)).Length];
_vital = new Vital[Enum.GetValues(typeof(VitalName)).Length];
_skill = new Skill[Enum.GetValues(typeof(SkillName)).Length];
SetupPrimaryAttributes();
SetupVitals();
SetupSkills();
}
public string Name
{
get{ return _name; }
set{ _name = value; }
}
public int Level
{
get{ return _level; }
set{ _level = value; }
}
public uint FreeXP
{
get{ return _freeXP; }
set{ _freeXP = value; }
}
public void AddXP(uint xp)
{
_freeXP += xp;
CalculateLevel();
}
//take avg of all player skills assign player level
public void CalculateLevel()
{
}
private void SetupPrimaryAttributes()
{
for(int cnt = 0; cnt > _primaryAttribute.Length; cnt++)
{
_primaryAttribute[cnt] = new Attribute();
}
}
private void SetupVitals()
{
for(int cnt = 0; cnt > _vital.Length; cnt++)
{
_vital[cnt] = new Vital();
}
}
private void SetupSkills()
{
for(int cnt = 0; cnt > _skill.Length; cnt++)
{
_skill[cnt] = new Skill();
}
}
public Attribute GetPrimaryAttribute(int index)
{
return _primaryAttribute[index];
}
public Vital GetVital(int index)
{
return _vital[index];
}
public Skill GetSkill(int index)
{
return _skill[index];
}
private void SetupVitalModifiers()
{
//health
GetVital((int)VitalName.Health).AddModifier(new ModifyingAttribute
{attribute = GetPrimaryAttribute((int)AttributeName.Constitution), ratio = 0.5f});
//energy
GetVital((int)VitalName.Energy).AddModifier(new ModifyingAttribute
{attribute = GetPrimaryAttribute((int)AttributeName.Constitution), ratio = 1});
//mana
GetVital((int)VitalName.Mana).AddModifier(new ModifyingAttribute
{attribute = GetPrimaryAttribute((int)AttributeName.Willpower), ratio = 1});
}
private void SetupSkillModifiers()
{
//melee offense
GetSkill((int)SkillName.Melee_Offense).AddModifier(new ModifyingAttribute
{attribute = GetPrimaryAttribute((int)AttributeName.Might), ratio = .33f});
GetSkill((int)SkillName.Melee_Offense).AddModifier(new ModifyingAttribute
{attribute = GetPrimaryAttribute((int)AttributeName.Nimbleness), ratio = .33f});
//melee defense
GetSkill((int)SkillName.Melee_Offense).AddModifier(new ModifyingAttribute
{attribute = GetPrimaryAttribute((int)AttributeName.Speed), ratio = .33f});
GetSkill((int)SkillName.Melee_Offense).AddModifier(new ModifyingAttribute
{attribute = GetPrimaryAttribute((int)AttributeName.Constitution), ratio = .33f});
//ranged offense
GetSkill((int)SkillName.Melee_Offense).AddModifier(new ModifyingAttribute
{attribute = GetPrimaryAttribute((int)AttributeName.Concentration), ratio = .33f});
GetSkill((int)SkillName.Melee_Offense).AddModifier(new ModifyingAttribute
{attribute = GetPrimaryAttribute((int)AttributeName.Speed), ratio = .33f});
//ranged defense
GetSkill((int)SkillName.Melee_Offense).AddModifier(new ModifyingAttribute
{attribute = GetPrimaryAttribute((int)AttributeName.Speed), ratio = .33f});
GetSkill((int)SkillName.Melee_Offense).AddModifier(new ModifyingAttribute
{attribute = GetPrimaryAttribute((int)AttributeName.Nimbleness), ratio = .33f});
//magic offense
GetSkill((int)SkillName.Melee_Offense).AddModifier(new ModifyingAttribute
{attribute = GetPrimaryAttribute((int)AttributeName.Concentration), ratio = .33f});
GetSkill((int)SkillName.Melee_Offense).AddModifier(new ModifyingAttribute
{attribute = GetPrimaryAttribute((int)AttributeName.Willpower), ratio = .33f});
//magic defense
GetSkill((int)SkillName.Melee_Offense).AddModifier(new ModifyingAttribute
{attribute = GetPrimaryAttribute((int)AttributeName.Concentration), ratio = .33f});
GetSkill((int)SkillName.Melee_Offense).AddModifier(new ModifyingAttribute
{attribute = GetPrimaryAttribute((int)AttributeName.Willpower), ratio = .33f});
}
public void StatUpdate()
{
for(int cnt = 0; cnt < _vital.Length; cnt++)
_vital[cnt].Update();
for(int cnt = 0; cnt < _skill.Length; cnt++)
_skill[cnt].Update();
}
}
anyone? Anyone?
I really don’t want to post a second thread about the same problem…