This question was
closed Jun 02 at 08:10 AM by
andrew-lukasik for the following reason:
The question is answered, right answer was accepted
Question by
fireblacksage · Jun 02 at 08:08 AM ·
spritesimages
I am trying to make my sprite show up as an image from a card database.
Card Database.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class CardDatabase : MonoBehaviour
{
public static List<Card> cardList = new List<Card>();
private void Awake()
{
cardList.Add(new Card(0, "Apple", 1, 1, 1, Resources.Load<Sprite>("111b")));
cardList.Add(new Card(1, "So", 1, 1, 2, Resources.Load<Sprite>("112b")));
}
}
Display Card.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
public class DisplayCard : MonoBehaviour
{
public List<Card> displayCard = new List<Card>();
public int displayId;
public int id;
public string cardName;
public int speed;
public int attack;
public int defense;
public Sprite spriteImage;
public Text nameText;
public Text speedText;
public Text attackText;
public Text defenseText;
public Image artImage;
// Start is called before the first frame update
void Start()
{
displayCard[0] = CardDatabase.cardList[displayId];
}
// Update is called once per frame
void Update()
{
id = displayCard[0].id;
cardName = displayCard[0].cardName;
speed = displayCard[0].speed;
attack = displayCard[0].attack;
defense = displayCard[0].defense;
spriteImage = displayCard[0].spriteImage;
nameText.text = " " + cardName;
speedText.text = " " + speed;
attackText.text = " " + attack;
defenseText.text = " " + defense;
artImage.sprite = spriteImage;
}
}
Comment
Best Answer
Answer by fireblacksage · Jun 02 at 02:56 AM
I solved it
void Start()
{
displayCard[0] = CardDatabase.cardList[displayId];
rend = GetComponent<Image>();
}
// Update is called once per frame
void Update()
{
id = displayCard[0].id;
cardName = displayCard[0].cardName;
speed = displayCard[0].speed;
attack = displayCard[0].attack;
defense = displayCard[0].defense;
imageName = displayCard[0].imageName;
spriteImage = Resources.Load<Sprite>(imageName);
rend.sprite = spriteImage;
nameText.text = " " + cardName;
speedText.text = " " + speed;
attackText.text = " " + attack;
defenseText.text = " " + defense;
rend.sprite = spriteImage;
}