Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Help...

Discussion in 'Formats & External Tools' started by ShaunChad99, Apr 30, 2020.

  1. ShaunChad99

    ShaunChad99

    Joined:
    Apr 23, 2020
    Posts:
    26
    Getting this error: Assets\DisplayInventory.cs(42,66): error CS0246: The type or namespace name 'Image' could not be found (are you missing a using directive or an assembly reference?) Please help thanks







    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using TMPro;
    5.  
    6. public class DisplayInventory : MonoBehaviour
    7. {
    8.     public GameObject inventoryPrefab;
    9.     public InventoryObject inventory;
    10.     public int X_START;
    11.     public int Y_START;
    12.     public int X_SPACE_BETWEEN_ITEM;
    13.     public int NUMBER_OF_COLUMN;
    14.     public int Y_SPACE_BETWEEN_ITEMS;
    15.     Dictionary<InventorySlot, GameObject> itemDisplay = new Dictionary<InventorySlot, GameObject>();
    16.  
    17.     //Start is called before the first frame update
    18.     void Start()
    19.     {
    20.         CreateDisplay();
    21.     }
    22.  
    23.      //Update is called once per frame
    24.     void Update()
    25.     {
    26.         UpdateDisplay();
    27.     }
    28.  
    29.     public void UpdateDisplay()
    30.     {
    31.      for (int i = 0; i < inventory.Container.Items.Count; i++)
    32.        {
    33.             InventorySlot slot = inventory.Container.Items[i];
    34.  
    35.             if (itemDisplay.ContainsKey(slot))
    36.             {
    37.                 itemDisplay[slot].GetComponentInChildren<TextMeshProUGUI>().text = slot.amount.ToString("n0");
    38.             }
    39.             else
    40.             {
    41.                 var obj = Instantiate(inventoryPrefab, Vector3.zero, Quaternion.identity, transform);
    42.                 obj.transform.GetChild(0).GetComponentInChildren<Image>().sprite = inventory.database.GetItem[slot.item.Id].uiDisplay;
    43.                 obj.GetComponent<RectTransform>().localPosition = GetPosition(i);
    44.                 obj.GetComponentInChildren<TextMeshProUGUI>().text = slot.amount.ToString("n0");
    45.                 itemDisplay.Add(inventory.Container.Items[i], obj);
    46.             }
    47.         }
    48.     }
    49.  
    50.     public void CreateDisplay()
    51.     {
    52.         for(int i = 0; i < inventory.Container.Items.Count; i++)
    53.         {
    54.             InventorySlot slot = inventory.Container.Items[i];
    55.  
    56.             var obj = Instantiate(inventoryPrefab, Vector3.zero, Quaternion.identity, transform);
    57.             obj.transform.GetChild(0).GetComponentInChildren<Image>().sprite = inventory.database.GetItem[slot.item.Id].uiDisplay;
    58.             obj.GetComponent<RectTransform>().localPosition = GetPosition(i);
    59.             obj.GetComponentInChildren<TextMeshProUGUI>().text = slot.amount.ToString("n0");
    60.             itemDisplay.Add(slot, obj);
    61.         }
    62.     }
    63.  
    64.     public Vector3 GetPosition(int i)
    65.     {
    66.         return new Vector3(X_START + (X_SPACE_BETWEEN_ITEM * (i % NUMBER_OF_COLUMN)),Y_START + (-Y_SPACE_BETWEEN_ITEMS * (i / NUMBER_OF_COLUMN)), 0f);
    67.     }
    68. }
     
  2. Mauri

    Mauri

    Joined:
    Dec 9, 2010
    Posts:
    2,663
    You're missing the
    using UnityEngine.UI;
    namespace, could that be?
     
  3. ShaunChad99

    ShaunChad99

    Joined:
    Apr 23, 2020
    Posts:
    26
    Thank You