W
W
Wadim_wadim20002020-05-25 14:58:16
C++ / C#
Wadim_wadim2000, 2020-05-25 14:58:16

C# can't find name or namespace name, what should I do?

the code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;

public class Inventory : MonoBehaviour
{
    public List<ItemInventory> items = new List<ItemInventory>();

    public GameObject gameObjectShow;

    public GameObject InventoryObject;

    public int maxCount;

    public DataBase data;

    public void AddItem(int id, Item item, int count)
    {
        items[id].id = item.id;
        items[id].count = count;
        items[id].itemGameObject.GetComponent<Image>().sprite = item.image; 

        if(count > 1 && item.id != 0)
        {
            items[id].itemGameObject.GetComponentInChildren<Text>().text = count.ToString();
        }
        else
        {
            items[id].itemGameObject.GetComponentInChildren<Text>().text = "";
        }
    }
    public void AddInventoryItem(int id, ItemInventory invItem)
    {
        items[id].id = invItem.id;
        items[id].count = invItem.count;
        items[id].itemGameObject.GetComponent<Image>().sprite = data.items[invItem.id].spr;

        if (invItem.count > 1 && invItem.id != 0)
        {
            items[id].itemGameObject.GetComponentInChildren<Text>().text = invItem.count.ToString();
        }
        else
        {
            items[id].itemGameObject.GetComponentInChildren<Text>().text = "";
        }
    }
    public void AddGraphics()
    {
        for(int i = 0; i < maxCount; i++)
        {
            GameObject newItem = Instantiate(gameObjectShow, InventoryObject.transform) as GameObject;

            newItem.name = i.ToString();
            ItemInventory ii = new ItemInventory();
            ii.itemGameObject = newItem;

            RectTransform rt = newItem.GetComponent<RectTransform>();
            rt.localPosition = new Vector3(0, 0, 0);
            rt.localScale = new Vector3(1, 1, 1);
            newItem.GetComponentInChildren<RectTransform>().localScale = new Vector3(1, 1, 1);

            Button tempButton = newItem.GetComponent<Button>();

            items.Add(ii);


        }
    }
}
[System.Serializable]
public class ItemInventory
{
    public int id;
    public GameObject itemGameObject;

    public int count;

}


script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class DataBase : MonoBehaviour
{
    public List<Item> items = new List<Item>();
    void Start()
    {
              
    }
    [System.Serializable]
    public class Item
    {
        public string name; // id предмета
        public Sprite spr; // его спрайт
    }
}


Ошибка CS0246 Не удалось найти тип или имя пространства имен "Item" (возможно, отсутствует директива using или ссылка на сборку).

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
freeExec, 2020-05-25
@Wadim_wadim2000

I also don't see where you have described the property imagein the classItem

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question