I am currently working on setting up a script to save character data including Vitals, Attributes, ExpToLevel, BaseValue, and CurValue. While working on the script, I messed something up with the ModifyingAttribute sections somewhere. I am very new to scripting and have been following tutorials, I am very stuck on this part because I can not find what is wrong. Any information regarding a solution would be very helpful. Code is in C#.
error CS0246: The type or namespace name `ModifyingAttribute’ could not be found. Are you missing a using directive or an assembly reference? is displayed on every line in BaseCharacter.cs where the term ModifyingAttribute is used, this began after applying the name to string, may have something to do with pcClass.GetVital(cnt).GetModifyingAttributesString (); on line 37. in GameSettings.cs
Other errors include:
error CS1502: The best overloaded method match for `ModifiedStat.AddModifier(ModifiedStat.ModifyingAt tribute)’ has some invalid arguments repeated in all lines where Modifying Attributes are located in BaseCharacter.cs
error CS1503: Argument #1' cannot convert
object’ expression to type `ModifiedStat.ModifyingAttribute’ repeated in all lines where Modifying Attributes are located in BaseCharacter.cs as well.
BaseCharacter.cs
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.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 FreeExp {
get{ return _freeExp; }
set{ _freeExp = value;}
}
public void AddExp(uint exp) {
_freeExp += exp;
CalculateLevel();
}
//take avg of all of the players skills and assign that as the player level.
public void CalculateLevel() {
}
private void SetupVitals() {
for(int cnt = 0; cnt <_vital.Length; cnt++)
_vital[cnt] = new Vital();
SetupVitalModifiers();
}
private void SetupPrimaryAttributes() {
for(int cnt = 0; cnt <_primaryAttribute.Length; cnt++)
_primaryAttribute[cnt] = new Attribute();
}
private void SetupSkills() {
for(int cnt = 0; cnt <_skill.Length; cnt++)
_skill[cnt] = new Skill();
SetupSkillModifiers();
}
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(GetPrimaryAttribute((int)AttributeName.Stamina), 3.5f)); <----(Error 'ModifyingAttribute' could not be found)
//energy
GetVital((int)VitalName.Energy).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Agility), 3.5f)); <----(Error 'ModifyingAttribute' could not be found)
//mana
GetVital((int)VitalName.Mana).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Intelligence), 3.5f)); <----(Error 'ModifyingAttribute' could not be found)
//blood
GetVital((int)VitalName.Blood).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Sanguinem), 3.5f)); <----(Error 'ModifyingAttribute' could not be found)
//defence
GetVital((int)VitalName.Defence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Armor), 4.5f)); <----(Error 'ModifyingAttribute' could not be found)
}
private void SetupSkillModifiers() {
//Melee Offence
GetSkill((int)SkillName.Melee_Offence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Strength), 1)); <----(Error 'ModifyingAttribute' could not be found)
GetSkill((int)SkillName.Melee_Offence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Attack_Power), 1)); <----(Error 'ModifyingAttribute' could not be found)
GetSkill((int)SkillName.Melee_Offence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Critical_Strike_Rating), 1)); <----(Error 'ModifyingAttribute' could not be found)
//Melee Defence
GetSkill((int)SkillName.Melee_Defence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Armor), 2.5f)); <----(Error 'ModifyingAttribute' could not be found)
//Ranged Offence
GetSkill((int)SkillName.Ranged_Offence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Agility), 1)); <----(Error 'ModifyingAttribute' could not be found)
GetSkill((int)SkillName.Ranged_Offence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Critical_Strike_Rating), 1)); <----(Error 'ModifyingAttribute' could not be found)
GetSkill((int)SkillName.Ranged_Offence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Attack_Power), 1)); <----(Error 'ModifyingAttribute' could not be found)
//Ranged Defence
GetSkill((int)SkillName.Ranged_Defence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Armor), 2.5f)); <----(Error 'ModifyingAttribute' could not be found)
//Magic Offence
GetSkill((int)SkillName.Magic_Offence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Intelligence), 1)); <----(Error 'ModifyingAttribute' could not be found)
GetSkill((int)SkillName.Magic_Offence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Spell_Power), 1)); <----(Error 'ModifyingAttribute' could not be found)
GetSkill((int)SkillName.Magic_Offence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Critical_Strike_Rating), 1)); <----(Error 'ModifyingAttribute' could not be found)
//Magic Defence
GetSkill((int)SkillName.Magic_Defence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Armor), 2.5f)); <----(Error 'ModifyingAttribute' could not be found)
//Blood Offence
GetSkill((int)SkillName.Blood_Offence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Sanguinem), 1)); <----(Error 'ModifyingAttribute' could not be found)
GetSkill((int)SkillName.Blood_Offence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Blood_Power), 1)); <----(Error 'ModifyingAttribute' could not be found)
GetSkill((int)SkillName.Blood_Offence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Spell_Power), 1)); <----(Error 'ModifyingAttribute' could not be found)
GetSkill((int)SkillName.Blood_Offence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Critical_Strike_Rating), 1)); <----(Error 'ModifyingAttribute' could not be found)
//Blood Defence
GetSkill((int)SkillName.Blood_Defence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Armor), 2.5f)); <----(Error 'ModifyingAttribute' could not be found)
}
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();
}
}
ModifiedStat.cs
using System.Collections.Generic;
public class ModifiedStat : BaseStat {
private List<ModifyingAttribute> _mods; //A List of Attributes that modify the stat
private int _modValue; //The amount 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 string GetModifyingAttributesString() {
string temp;
for(int cnt = 0; cnt < _mods.Count; cnt++) {
UnityEngine.Debug.Log(_mods[cnt].attribute.Name);
}
return "";
}
public struct ModifyingAttribute {
public Attribute attribute;
public float ratio;
public ModifyingAttribute(Attribute att, float rat) {
attribute = att;
ratio = rat;
}
}
}
GameSettings.cs
using UnityEngine;
using System.Collections;
using System;
public class GameSettings : MonoBehaviour {
void Awake() {
DontDestroyOnLoad(this);
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
public void SaveCharacterData() {
GameObject pc = GameObject.Find("pc");
PlayerCharacter pcClass = pc.GetComponent<PlayerCharacter>();
PlayerPrefs.SetString("Player Name", pcClass.Name);
for(int cnt = 0; cnt < Enum.GetValues(typeof(AttributeName)).Length; cnt++) {
PlayerPrefs.SetInt(((AttributeName)cnt).ToString() + " - Base Value", pcClass.GetPrimaryAttribute(cnt).BaseValue);
PlayerPrefs.SetInt(((AttributeName)cnt).ToString() + " - Exp To Level", pcClass.GetPrimaryAttribute(cnt).ExpToLevel);
}
for(int cnt = 0; cnt < Enum.GetValues(typeof(VitalName)).Length; cnt++) {
PlayerPrefs.SetInt(((VitalName)cnt).ToString() + " - Base Value", pcClass.GetVital(cnt).BaseValue);
PlayerPrefs.SetInt(((VitalName)cnt).ToString() + " - Exp To Level", pcClass.GetVital(cnt).ExpToLevel);
PlayerPrefs.SetInt(((VitalName)cnt).ToString() + " - Cur Value", pcClass.GetVital(cnt).CurValue);
pcClass.GetVital(cnt).GetModifyingAttributesString();
}
}
public void LoadCharacterData() {
}
}
CharacterGenerator.cs
using System.Collections;
using System; //used for the Enum class
public class CharacterGenerator : MonoBehaviour {
private PlayerCharacter _toon;
private const int STARTING_POINTS= 500;
private const int MIN_STARTING_ATTRIBUTE_VALUE = 10;
private const int STARTING_VALUE = 50;
private int pointsLeft;
private const int OFFSET = 5;
private const int LINE_HEIGHT = 20;
private const int STAT_LABEL_WIDTH = 150;
private const int BASEVALUE_LABEL_WIDTH = 30;
private const int BUTTON_WIDTH = 20;
private const int BUTTON_HEIGHT = 20;
private const int statStartingPos = 40;
public GUIStyle myStyle;
public GUISkin mySkin;
public GameObject playerPrefab;
// Use this for initialization
void Start () {
GameObject pc = Instantiate(playerPrefab, Vector3.zero, Quaternion.identity) as GameObject;
pc.name = "pc";
// _toon = new PlayerCharacter();
// _toon.Awake();
_toon = pc.GetComponent<PlayerCharacter>();
pointsLeft = STARTING_POINTS;
for(int cnt = 0; cnt < Enum.GetValues(typeof(AttributeName)).Length; cnt++) {
_toon.GetPrimaryAttribute(cnt).BaseValue = STARTING_VALUE;
pointsLeft -= (STARTING_VALUE - MIN_STARTING_ATTRIBUTE_VALUE);
}
_toon.StatUpdate();
}
// Update is called once per frame
void Update () {
}
void OnGUI() {
// GUI.skin = mySkin;
DisplayName();
DisplayPointsLeft();
DisplayAttributes();
DisplayVitals();
DisplaySkills();
DisplayCreateButton();
}
private void DisplayName() {
GUI.Button(new Rect(Screen.width / 2 - 175, //x
statStartingPos + (10 * (LINE_HEIGHT * 2.5f) + statStartingPos * 4.5f), //y
100, //width
LINE_HEIGHT //height
), "Name");
_toon.Name = GUI.TextField(new Rect(Screen.width / 2 - 50, //x
statStartingPos + (10 * (LINE_HEIGHT * 2.5f) + statStartingPos * 4.5f), //y
100, //width
LINE_HEIGHT //height
),_toon.Name);
}
private void DisplayAttributes() {
for(int cnt = 0; cnt < Enum.GetValues(typeof(AttributeName)).Length; cnt++) {
GUI.Label(new Rect(OFFSET * 2, //x
statStartingPos + (cnt * LINE_HEIGHT * 2), //y
STAT_LABEL_WIDTH, //width
LINE_HEIGHT //height
), ((AttributeName)cnt).ToString());
GUI.Label(new Rect( STAT_LABEL_WIDTH + OFFSET + LINE_HEIGHT, //x
statStartingPos + (cnt * LINE_HEIGHT * 2), //y
BASEVALUE_LABEL_WIDTH, //width
LINE_HEIGHT //height
), _toon.GetPrimaryAttribute(cnt).AdjustedBaseValue.ToString());
if(GUI.Button(new Rect( OFFSET + STAT_LABEL_WIDTH + BASEVALUE_LABEL_WIDTH + OFFSET * 6, //x
statStartingPos + (cnt * BUTTON_HEIGHT * 2), //y
BUTTON_WIDTH, //width
BUTTON_HEIGHT //height
), "-")) {
if(_toon.GetPrimaryAttribute(cnt).BaseValue > MIN_STARTING_ATTRIBUTE_VALUE) {
_toon.GetPrimaryAttribute(cnt).BaseValue--;
pointsLeft++;
_toon.StatUpdate();
}
}
if(GUI.Button(new Rect( OFFSET + STAT_LABEL_WIDTH + BASEVALUE_LABEL_WIDTH + BUTTON_WIDTH + OFFSET * 7.5f, //x
statStartingPos + (cnt * BUTTON_HEIGHT *2), //y
BUTTON_WIDTH, //width
BUTTON_HEIGHT //height
), "+")) {
if(pointsLeft > 0) {
_toon.GetPrimaryAttribute(cnt).BaseValue++;
pointsLeft--;
_toon.StatUpdate();
}
}
}
}
private void DisplayVitals() {
for(int cnt = 0; cnt < Enum.GetValues(typeof(VitalName)).Length; cnt++) {
GUI.Label(new Rect( OFFSET * 2, //x
statStartingPos + ((cnt + 7) * (LINE_HEIGHT * 2.5f) + statStartingPos * 2), //y
STAT_LABEL_WIDTH, //width
LINE_HEIGHT //height
), ((VitalName)cnt).ToString());
GUI.Label(new Rect( OFFSET + STAT_LABEL_WIDTH + LINE_HEIGHT, //x
statStartingPos + ((cnt + 7) * (LINE_HEIGHT * 2.5f) + statStartingPos * 2), //y
BASEVALUE_LABEL_WIDTH, //width
LINE_HEIGHT //height
), _toon.GetVital(cnt).AdjustedBaseValue.ToString());
}
}
private void DisplaySkills() {
for(int cnt = 0; cnt < Enum.GetValues(typeof(SkillName)).Length; cnt++) {
GUI.Label(new Rect( OFFSET + STAT_LABEL_WIDTH + BASEVALUE_LABEL_WIDTH + BUTTON_WIDTH * 2 + OFFSET * (OFFSET * 2), //x
statStartingPos + (cnt * (LINE_HEIGHT * 2)), //y
STAT_LABEL_WIDTH, //width
LINE_HEIGHT //height
),((SkillName)cnt).ToString());
GUI.Label(new Rect( OFFSET + STAT_LABEL_WIDTH + BASEVALUE_LABEL_WIDTH + BUTTON_WIDTH * 2 + OFFSET * (OFFSET * 2.5f) + STAT_LABEL_WIDTH, //x
statStartingPos + (cnt * (LINE_HEIGHT * 2)), //y
BASEVALUE_LABEL_WIDTH, //width
LINE_HEIGHT //height
), _toon.GetSkill(cnt).AdjustedBaseValue.ToString());
}
}
private void DisplayPointsLeft() {
GUI.Label(new Rect(STAT_LABEL_WIDTH + OFFSET * 3.5f, 10, 100, 25), "Points Left: " + pointsLeft.ToString());
}
private void DisplayCreateButton() {
if(GUI.Button(new Rect(Screen.width / 2 - 50, statStartingPos + (10 * (LINE_HEIGHT * 2.5f) + statStartingPos * 5.5f), 100, LINE_HEIGHT), "Create")){
GameSettings gsScript = GameObject.Find("__GameSettings").GetComponent<GameSettings>();
//change the cur value of the vitals to the max modified value of that vital
gsScript.SaveCharacterData();
Application.LoadLevel("Europe");
}
}
}