Sunday 5 August 2018

C# How to convert Enum Value to Int

I have got an Enum List



public enum SkillName {
Mele_Offence,
Mele_Defence

}


Then my skills are setted up and modified on Player class



private void SetupSkillModifires () {
// mele Offence
GetSkill((int)SkillName.Mele_Offence).AddModifire(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Strength), 2));
GetSkill((int)SkillName.Mele_Offence).AddModifire(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Agility), 1));
//mele Deffence

GetSkill((int)SkillName.Mele_Defence).AddModifire(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Agility), 1));
GetSkill((int)SkillName.Mele_Defence).AddModifire(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Vitality), 2));
//Magic Offence

}


Then I have converted it to string and displayed it in scene.



private void DisplayAttributes() {

for(int cnt = 0; cnt < Enum.GetValues(typeof(AttributeName)).Length; cnt++) {
GUI.Label (new Rect (130, 60 + (cnt * 20), 100, 20), ((AttributeName)cnt).ToString());
GUI.Label (new Rect (300, 60 + (cnt * 20), 30, 25), _toon.GetPrimaryAttribute(cnt).AdjustedBaseValue.ToString());
if (GUI.Button (new Rect (265, 60 + (cnt * 20), 20, 20), "-")) {
if (_toon.GetPrimaryAttribute(cnt).BaseValue > MIN_STARTING_ATTRIBUTE_VALUE) {
_toon.GetPrimaryAttribute (cnt).BaseValue--;
pointsLeft++;
_toon.StatUpdate ();
}



How to assign theese skills to Player attack value?
I have this error.
error CS0029: Cannot implicitly convert type Skil to int?

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...