Hello everyone!
My game will have a lot of skills with specific values each (e.g. Range, CastSpeed, Damage, etc), and I believe that the best way to do it is by using constructors. Also, I will need to retrieve those values in a lot of different parts of the code, so I created a method for it. Here’s the code:
public class SkillDatabase {
public int Range;
public int CastSpeed;
public int Damage;
public SkillDatabase (int Range, int CastSpeed, int Damage){
this.Range = Range;
this.CastSpeed = CastSpeed;
this.Damage = Damage;
}
}
void Start (){
SkillDatabase Ice = new SkillDatabase (5, 3, 5);
SkillDatabase Fire = new SkillDatabase (4, 4, 6);
Debug.Log (GetValue ("Ice", "Cast Speed"));
Debug.Log (GetValue ("Fire", "Damage"));
}
public int GetValue (string skill, string value){
switch (skill){
case "Ice":
if (value == "Range")
return Ice.Range;
if (value == "Cast Speed")
return Ice.CastSpeed;
if (value == "Damage")
return Ice.Damage;
break;
case "Fire":
if (value == "Range")
return Fire.Range;
if (value == "Cast Speed")
return Fire.CastSpeed;
if (value == "Damage")
return Fire.Damage;
break;
}
return 0;
}
However, I can’t access my constructors inside my method, I get error “The name `Fire’ does not exist in the current context”.
I also tried putting the method inside the class, but it causes me a problem because I can’t specify which skill I want to access with a string (I have to use Ice.GetValue() instead).
Can someone please help? I also accept suggestions of better ways of achieving my skill database goal ![]()