- Home /
How can I assign a UI text and a sprite to variables?
Hello, I am not good in programming. Can someone please help me with this code? I'm supposed to do a card game and is it possible to assign a UI text to the variable cardnumber and a Sprite to the variable cardcolor? And how?
............................................................................................................
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Card
{ public int cardvalue;
public Color cardcolor;
public Card(int _cardvalue, Color _cardcolor)
{
_cardcolor = cardcolor;
_cardvalue = cardvalue;
}
}
public class Cards : MonoBehaviour { public List CardDeck; public Stack cardstack;
public Text CardNumber;
public GameObject CardColor;
void Start()
{
CardDeck = new List<Card>();
cardstack = new Stack<Card>();
for (int i = 1; i < 8; i++)
{
CardDeck.Add(new Card(i, Color.red));
CardDeck.Add(new Card(i, Color.blue));
CardDeck.Add(new Card(i, Color.yellow));
CardDeck.Add(new Card(i, Color.green));
}
while (CardDeck.Count > 0)
{
int cardchosen = Random.Range(0, CardDeck.Count -1);
cardstack.Push(CardDeck[cardchosen]);
CardDeck.RemoveAt(cardchosen);
}
foreach (Card card in cardstack)
{
Debug.Log(card.cardvalue + "color" + card.cardcolor);
}
}
void Update()
{
}
}
Comment
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Voting System Using List (C#) 1 Answer
Limit the size/capacity of a list 3 Answers
Object Pooling for Class Pattern 0 Answers