I am using an enumerator in my script, and at the moment it has a very simple enum:
public enum Item
{
Wood,
Stone
}
With this enum, I am able to do stuff that you are normally able to do with an enum, such as int foo = (int)Item.Wood
, which sets foo
equal to 0. However, there is a point in my script where I want to set an int
variable using the enum, but I don't know what the item will be. For example:
public enum Item
{
Wood,
Stone
}
string ItemString = "Stone";
int foo = (int)Item.ItemString
However, this doesn't work because now the script is looking for an enumeration called ItemString, instead of looking at the value of ItemString and finding the enumeration of that. Anybody know what I can do in this situation? If necessary I can provide more details and clarification.
Edit: This post partially answers my question, but the accepted answer better shows how to implement the answer from the linked post.