- Home /
Help About Unity3d Tutorial - Base Character Class Hack and Slash Tutorial
I am using 3.3 Unity
i got a bunch of errors appearing on the console it says 1. VitalName could not be found 2. The best overloaded method match for System.Enum.GetValues(System.Type)' has some invalid arguments 3. Argument
#1' cannot convert object' expression to type
System.Type' 4. Also the SkillName have the same Error as 1-3
using UnityEngine;
using System.Collections;
using System; //added to acces 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 the players skill and assign that as the 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(GetPrimaryAttribute((int)AttributeName.Constitution), .5f));
//energy
GetVital((int)VitalName.Energy).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Constitution), 1));
}
public void SetupSkillModifiers() {
//melee offence
GetSkill((int)SkillName.Melee_Offence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Might), .33f));
GetSkill((int)SkillName.Melee_Offence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Nimbleness), .33f));
//melee defence
GetSkill((int)SkillName.Melee_Defence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Speed), .33f));
GetSkill((int)SkillName.Melee_Defence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Constitution), .33f));
//ranged offence
GetSkill((int)SkillName.Ranged_Offence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Concentration), .33f));
GetSkill((int)SkillName.Ranged_Offence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Speed), .33f));
//ranged defence
GetSkill((int)SkillName.Ranged_Defence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Speed), .33f));
GetSkill((int)SkillName.Ranged_Defence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Nimbleness), .33f));
//magic offence
GetSkill((int)SkillName.Magic_Offence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Concentration), .33f));
GetSkill((int)SkillName.Magic_Offence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.WillPower), .33f));
//magic defence
GetSkill((int)SkillName.Magic_Defence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Concentration), .33f));
GetSkill((int)SkillName.Magic_Defence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.WillPower), .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();
}
}
You may want to first format your code properly in the question using the 10101 icon. Then you might want to have a link to the tutorial you are working on so others can help see what your problem is. Asking a question with a wall of code that is badly formatted is not going to get you any answers.
What are VitalName and SkillName? Do you have a script with that name? Do you have a script with the name Attribute?
Answer by coldfire2k · Jul 21, 2011 at 08:46 AM
@sir Meltdown thanks for that now i update my question and now its look clean and neat i dont know how to use that earlier. Sir here is the link to tutorial im working with
Unity3d Tutorial - Base Character Class 1/3 - 3/3
@sir Aldwoni yea i do have a script named Attribute I added an image below:
I dont know really know the causes of errors. :(
it's better when you create a comment ins$$anonymous$$d of an answer. I expect you need a script called VitalName and a script called SkillName
Answer by coldfire2k · Jul 21, 2011 at 09:02 AM
@sir Aldwoni
In my Vital script like in the pic above; i used a public enum to link Vital name, here it is.
public class Vital : ModifiedStat { private int _curValue;
public Vital() {
_curValue = 0;
ExpToLevel = 50;
LevelModifier = 1.1f;
}
public int CurValue {
get{
if(_curValue > AdjustedBaseValue)
_curValue = AdjustedBaseValue;
return _curValue;
}
set{ _curValue = value; }
}
public enum VitalName { Health, Energy, Mana } }