Вот код: < /p>
Код: Выделить всё
using UnityEngine;
using UnityEngine.Tilemaps;
using System;
using System.Collections.Generic;
public class InventoryDisplay : MonoBehaviour
{
public Transform[] hotbar;
public Transform[] inventoryUI;
[SerializeField]
public Inventory inventory;
public GameObject hotbarObject;
public GameObject inventoryObject;
void Start()
{
hotbar = hotbarObject.GetComponentsInChildren();
inventoryUI = inventoryObject.GetComponentsInChildren();
}
void Update()
{
InventoryCheck();
}
void InventoryCheck()
{
for (int i = 0; i < hotbar.Length; i++)
{
if (inventory.items[i] != Resources.Load("Items/Empty"))
{
hotbar[i].GetComponent().sprite = inventory.items[i].sprite;
}
else
{
print(hotbar[i]);
hotbar[i].GetComponent().sprite = null;
}
}
for (int i = hotbar.Length; i < inventoryUI.Length; i++)
{
if (inventory.items[i] != Resources.Load("Items/Empty"))
{
inventoryUI[i].GetComponent().sprite = inventory.items[i].sprite;
}
else
{
inventoryUI[i].GetComponent().sprite = null;
}
}
}
}
Вот снимок экрана для некоторой визуальной справки: < /p>
Скриншот экрана Unity < /p>
Любые идеи о том, почему он функционирует как это?
Подробнее здесь: https://stackoverflow.com/questions/793 ... e-children
Мобильная версия