UnityScripterAI
Discord ↗
Link Copied to Clipboard
×
"create a card based inventory"
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class CardInventory : MonoBehaviour { public List<Card> cards = new List<Card>(); public GameObject cardPrefab; public Transform cardParent; // Start is called before the first frame update void Start() { PopulateInventory(); } void PopulateInventory() { foreach (Card card in cards) { GameObject cardInstance = Instantiate(cardPrefab, cardParent); cardInstance.GetComponent<CardDisplay>().SetupCard(card); } } } [System.Serializable] public class Card { public string cardName; public Sprite cardImage; public string cardDescription; } public class CardDisplay : MonoBehaviour { public Text cardNameText; public Image cardImage; public Text cardDescriptionText; public void SetupCard(Card card) { cardNameText.text = card.cardName; cardImage.sprite = card.cardImage; cardDescriptionText.text = card.cardDescription; } }