i’m new on unity, i want to make a Card Game. in my making use of class card to represent the attributes of that class. then I used a list of cards in the deck class to hold classes there. i want to manipulate deck card, remove it, move its content ect.
- how do I access the list on class deck from the other class?.
- how I can move the contents from list of classes into a new list in another class?
- if you all have another better way, please tell me
- Please evaluate me if i’m wrong when implementing the code.
This my cards class
public class Cards : MonoBehaviour {
private string _type;
private string _action;
private int _gold;
public string Type
{
get { return _type; }
set { _type = value; }
}
public string Action
{
get { return _action; }
set { _action = value; }
}
public int Gold
{
get { return _gold; }
set { _gold = value; }
}
my Deck Class
public class DeckCard : MonoBehaviour {
public List<Cards> _cardsOnDeck;
HandCard hand;
void Start()
{
FirstDeck();
}
void FirstDeck()
{
_cardsOnDeck = new List<Cards>();
for(int i=0; i < 5; i++)
{
Cards cardGold = new Cards();
cardGold.Type = "Resource";
_cardsOnDeck.Add(cardGold);
}
for (int i = 0; i < 2; i++)
{
Cards cardAction = new Cards();
cardAction.Type = "Resource";
_cardsOnDeck.Add(cardAction);
}
}
my hand card class
public class HandCard : MonoBehaviour {
[SerializeField]
private List<Cards> _cardOnHand = new List<Cards>();
private DeckCard _drawedCard = new DeckCard();
public GameObject SpawnCard;
void Start()
{
_cardOnHand.AddRange(_drawedCard._cardsOnDeck);
}
void update()
{
Debug.Log(_cardOnHand[0].GetType());
}
Cards DrawCard()
{
if (_drawedCard._cardsOnDeck.Count == 0)
{
return null;
}
else
{
int _cardIndex = Random.Range(0, _drawedCard._cardsOnDeck.Count - 1);
Cards cardGO = _drawedCard._cardsOnDeck[_cardIndex];
_drawedCard._cardsOnDeck.RemoveAt(_cardIndex);
return cardGO;
}
}
public void DrawCardOnHand()
{
Cards spawnNew = Instantiate(SpawnCard, transform.position, Quaternion.identity).GetComponent<Cards>();
for (int i = 0; i < 5; i++)
{
_cardOnHand.Add(DrawCard());
spawnNew = _cardOnHand*;*
}
}
void removeCard()
{
int x = _drawedCard._cardsOnDeck.Count;
Debug.Log(x);
}
thanks for attention, sorry for my bad english