- Home /
Lists, Is a type but is used like a variable Problem C#
I've been trying to solve this problem for a couple of days now, Im working in an inventory System.
The name 'ItemType' does not exist in the current context
And the main one: 'ItemHandler' is a 'type' but is used like a 'variable' I think if I solve this one I will solve the other.
(The line of //Items Start is using another class) just pointing out.
Here's the code:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class Items : MonoBehaviour
{
public List<ItemHandler> itemsList = new List<ItemHandler>();
private Texture2D item1Icon;
private Texture2D item2Icon;
private Texture2D item3Icon;
void start()
{
//Icons start
//This loads the Icon Information
item1Icon = Resources.Load("Icons/Wood_Icon") as Texture2D;
//Items Start
itemsList.Add(ItemHandler(1, item1Icon, "Wood", "A wooden Log description", false, ItemType.Material));
}
}
Answer by NoseKills · Jun 25, 2015 at 03:49 PM
Use the 'new' keyword to call the constructor to create new objects.
itemList.Add(new ItemHandler(...)
To help you with the ItemType problem we'd need to know what ItemType is supposed to be. You are not declaring that as a variable in this class so it's another class? Make sure there are no typos, that you have a 'using' statement for its namespace if it's in a different namespace and make sure ItemType.Material is static since you are referencing it through the class name.
Thank you, Worked like a charm! At the end I needed to type the ItemHandler.ItemType. to call it. and then the other thing in this case "$$anonymous$$aterial" I solved it with this code: I hope this will solve other people issues.
itemsList.Add(new ItemHandler(1, item1Icon, "Wood", "A wooden Log description", false, ItemHandler.ItemType.$$anonymous$$aterial));
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
How to ignore base class? 1 Answer
[CLOSED] When I use this code that I made, it adds to the item catalogue too? [CLOSED] 1 Answer
List doesn't hold children's variables 1 Answer
How can I store game data outside of scripts.(e.g Total list of inventory items) 2 Answers