This is Almost the same error as before but This Stops the game totaly.
It points at lines:
44 and 18.
It doesn’t display the skills correctly like Melee_ Offence and mele_defence and so on.
I’m watching this tutorial:
using UnityEngine;
using System.Collections;
using System;
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()
{
DisplayName();
DisplayAttributes();
DisplayVitals();
DisplaySkills();
}
private void DisplayName()
{
GUI.Label(new Rect(10, 10, 50, 25), "Name:" );
_toon.Name = GUI.TextArea(new Rect(65, 10, 120, 25), _toon.Name);
}
private void DisplayAttributes()
{
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() );
}
}
private void DisplayVitals()
{
for(int cnt = 0; cnt < Enum.GetValues(typeof(VitalName)).Length; cnt++)
{
GUI.Label(new Rect(10, 40 + ((cnt + 7) * 25), 100, 25), ((VitalName)cnt).ToString() );
GUI.Label(new Rect(115, 40 + ((cnt + 7) * 25), 30, 25), _toon.GetVital(cnt).AdjustedBaseValue.ToString() );
}
}
private void DisplaySkills()
{
for(int cnt = 0; cnt < Enum.GetValues(typeof(SkillName)).Length; cnt++)
{
GUI.Label(new Rect(150, 40 + (cnt * 25), 100, 25), ((SkillName)cnt).ToString() );
GUI.Label(new Rect(255, 40 + (cnt * 25), 30, 25), _toon.GetSkill(cnt).AdjustedBaseValue.ToString() );
}
}
}
And this is the class where I get my SkillName and VitalName.
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 _freeExp;
private Attribute[] _primaryAttribute;
private Vital[] _vital;
private Skill[] _skill;
public void Awake()
{
_name = string.Empty;
_level = 0;
_freeExp = 0;
_primaryAttribute = new Attribute[Enum.GetNames(typeof(AttributeName)).Length];
_vital = new Vital[Enum.GetValues(typeof(VitalName)).Length];
_skill = new Skill[Enum.GetValues(typeof(SkillName)).Length];
SetupPrimaryAttribute();
SetupVitals();
SetupSkills();
}
public string Name
{
get{ return _name; }
set{ _name = value; }
}
public int Level
{
get{ return _level; }
set{ _level = value;}
}
public uint FreeExp
{
get{ return _freeExp; }
set{ _freeExp = value; }
}
public void AddExp(uint exp)
{
_freeExp += exp;
CalculateLevel();
}
//take average of all of the player skills and assign that as the player level.
public void CalculateLevel()
{
}
private void SetupPrimaryAttribute()
{
for(int cnt = 0; cnt < _primaryAttribute.Length; cnt++)
{
_primaryAttribute[cnt] = new Attribute();
}
}
private void SetupVitals()
{
for(int cnt = 0; cnt < _vital.Length; cnt++)
{
_primaryAttribute[cnt] = new Attribute();
}
}
private void SetupSkills()
{
for(int cnt = 0; cnt < _skill.Length; cnt++)
{
_primaryAttribute[cnt] = new Attribute();
}
}
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).AddModifer(new ModifyingAttribute{attribute = GetPrimaryAttribute((int)AttributeName.Wisdom), ratio = 0.5f});
//stamina
GetVital((int)VitalName.Stamina).AddModifer(new ModifyingAttribute{attribute = GetPrimaryAttribute((int)AttributeName.Strength), ratio = 1});
GetVital((int)VitalName.Stamina).AddModifer(new ModifyingAttribute{attribute = GetPrimaryAttribute((int)AttributeName.Speed), ratio = 1});
//mana
GetVital((int)VitalName.Mana).AddModifer(new ModifyingAttribute{attribute = GetPrimaryAttribute((int)AttributeName.Knowledge), ratio = 1});
GetVital((int)VitalName.Mana).AddModifer(new ModifyingAttribute{attribute = GetPrimaryAttribute((int)AttributeName.Wisdom), ratio = 1});
GetVital((int)VitalName.Mana).AddModifer(new ModifyingAttribute{attribute = GetPrimaryAttribute((int)AttributeName.Concentration), ratio = 1});
}
private void SetupSkillModifiers()
{
//melee offence
GetSkill((int)SkillName.Melee_Offence).AddModifer(new ModifyingAttribute{attribute = GetPrimaryAttribute((int)AttributeName.Strength), ratio = 0.33f});
//melee defence
GetSkill((int)SkillName.Melee_Defence).AddModifer(new ModifyingAttribute{attribute = GetPrimaryAttribute((int)AttributeName.Speed), ratio = 0.33f});
//magic offence
GetSkill((int)SkillName.Magic_Offense).AddModifer(new ModifyingAttribute{attribute = GetPrimaryAttribute((int)AttributeName.Wisdom), ratio = 0.33f});
GetSkill((int)SkillName.Magic_Offense).AddModifer(new ModifyingAttribute{attribute = GetPrimaryAttribute((int)AttributeName.Concentration), ratio = 0.33f});
//magic defence
GetSkill((int)SkillName.Magic_Defense).AddModifer(new ModifyingAttribute{attribute = GetPrimaryAttribute((int)AttributeName.Knowledge), ratio = 0.33f});
//ranged offence
GetSkill((int)SkillName.Ranged_Offence).AddModifer(new ModifyingAttribute{attribute = GetPrimaryAttribute((int)AttributeName.Speed), ratio = 0.33f});
GetSkill((int)SkillName.Ranged_Offence).AddModifer(new ModifyingAttribute{attribute = GetPrimaryAttribute((int)AttributeName.Concentration), ratio = 0.33f});
//ranged defence
GetSkill((int)SkillName.Ranged_Defence).AddModifer(new ModifyingAttribute{attribute = GetPrimaryAttribute((int)AttributeName.Speed), ratio = 0.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();
}
}
}