I have been trying to get back into Unity development, and have been refreshing myself with a tutorial series. I’m having a problem with one of the segments though, it involves 2 scripts which inherit from another script, and I am receiving the error from the topic.
The error occurs on line 29, character 56 of ModifiedStat, however it references all the way back to BaseStat.
What can I do to fix this while maintaining the same basic flow so I can keep up with the tutorial series?
The scrips are as follows:
BaseStat:
using System;
using UnityEngine;
public class BaseStat{
private int _baseValue; //Unmodified stat
private int _buffValue; // after buffs
private int _expToLevel;
private float _levelModifier;
public BaseStat()
{
_baseValue = 0;
_buffValue = 0;
_levelModifier = 1.1f;
_expToLevel = 100;
}
//set get
#region set get
public int BaseValue
{
get{return _baseValue;}
set{_baseValue = value; }
}
public int BuffValue
{
get{return _buffValue;}
set{_buffValue = value; }
}
public int ExpToLevel
{
get{return _expToLevel;}
set{_expToLevel = value; }
}
public float LevelModifier
{
get{return _levelModifier;}
set{_levelModifier = value; }
}
#endregion
private int CalculateExpToLevel()
{
return Mathf.FloorToInt((_expToLevel * _levelModifier)) ;
}
public void LevelUp()
{
_expToLevel = CalculateExpToLevel();
_baseValue++;
}
public int AdjustedBaseValue
{
get{ return _baseValue + _buffValue;}
}
}
Attribute:
using UnityEngine;
using System.Collections;
public class Attribute : BaseStat{
public Attribute()
{
ExpToLevel = 50;
LevelModifier = 1.05f;
}
}
public enum AttributeName
{
Might,
Constitution,
Nimbleness,
Speed,
Concentration,
Willpower,
Charisma
}
ModifiedStat:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class ModifiedStat : BaseStat {
private List<ModifyingAttribute> _mods; //List of attributes that modify this stat
private int _modValue; //Amount added to the baseValue from the modifiers
public ModifiedStat()
{
_mods = new List<ModifyingAttribute>();
_modValue = 0;
}
public void AddModifier(ModifyingAttribute mod)
{
_mods.Add (mod);
}
private void CalculateModValue()
{
_modValue = 0;
if(_mods.Count > 0)
{
foreach(ModifyingAttribute att in _mods)
{
_modValue += (int)(att.attribute.AdjustedBaseValue * att.ratio);
}
}
}
public new int AdjustedBaseValue
{
get{ return BaseValue + BuffValue + _modValue;}
}
public void Update()
{
CalculateModValue();
}
}
public struct ModifyingAttribute
{
public Attribute attribute;
public float ratio;
}