- Home /
Problem accessing enum from other class
I'm trying to check the enum of an item from a list of a class called Item. I get an error that says it can't access the static member with an instance reference.
Here are the scripts:
Item class:
[System.Serializable]
public class Item {
public string name;
public string desc;
public Rarity rarity;
public ItemType type;
public Texture2D icon;
public bool equipped;
public void ApplyState() {
if (equipped) {
Debug.Log("Add Stats");
} else {
Debug.Log("Remove Stats");
}
}
}
//Item Rarity
public enum Rarity {
common, //White
uncommon, //Blue
rare, //Yellow
legendary //Orange
}
//Item Type
public enum ItemType {
tool,
weapon,
food,
misc,
head,
body,
legs,
feet,
hand,
neck
}
part of Inventory Class:
public void InvenTool() {
GUI.Box (new Rect(0, 0, 200, Screen.height), "Tools");
for(int x = 0;x < items.Count;x++) {
if(items[x].type == items[x].type.tool) {
if(GUILayout.Button("" + items[x].name)) {
Debug.Log(items[x].desc);
}
}
}
if(GUI.Button (new Rect(10, 190, 180, 30), "Back")) {
NavigateTo("Sel");
}
}
I don't know what the problem is. I read that I'm supposed to be able to access enums from all classes, but it doesn't work. I would appreciate help with this.
The code above shows your enums to be outside of your Item class. Place them inside.
ins$$anonymous$$d of
items[x].type == items[x].type.tool
try
items[x].type == ItemType.tool
$$anonymous$$ake this question solved so people, like myself, don't think it is still unanswered.
Answer by Deadcow_ · Mar 12, 2014 at 06:52 AM
instead of
items[x].type == items[x].type.tool
try
items[x].type == ItemType.tool
Your answer
Follow this Question
Related Questions
An OS design issue: File types associated with their appropriate programs 1 Answer
Add random amount of random items from one list to another? 2 Answers
How to ignore base class? 1 Answer
Problem using variable of type CustomStat to indicate which player statistic to change 1 Answer
FPS weapons class structure 1 Answer