Hi all,
Let me preface with I have an advanced beginners knowledge of coding.
I am working on a card game where I would like to have 3 discreet types of cards. Plant, Status and Passive.
I want each card to have its own prefab. I also want to create the cards as Scriptable Objects. The different cards are given a cardType (Plant, Status or Passive) to help with instantiation etc.
I am unsure about the best way to handle this.
Previously I have ran with the idea of having three scripts for the different SO (i.e PlantSO, StatusSO and PassiveSO) then bump into the issue of sending this to the CardController script. Particularly when inheriting information (hope this is the correct term).
i.e
public void Initialize(Card card, int ownerID)
{
this.card = new Card(card);
{
this.card.ownerID = ownerID;
}
illustration.sprite = card.illustration;
cardName.text = card.cardName;
description.text = card.description;
days.text = card.days.ToString();
harvest.text = card.harvest.ToString();
orignalParent = transform.parent;
}
I have also tried a different method where the three cards are created in one SO and, again, sent to the CardController.
i.e
private void CollectInfoFromCardSO()
{
if (cardData == null)
{
Destroy(this.gameObject);
return;
}
if (cardType == CardTypes.PLANT)
{
cardName = cardData.cardName;
cardDays = cardData.cardDays;
cardHarvest = cardData.cardHarvest;
cardFlavour = cardData.cardFlavour;
}
else if (cardType == CardTypes.STATUS)
{
cardName = cardData.cardName;
cardDescription = cardData.cardDescription;
cardFlavour = cardData.cardFlavour;
}
else if ( cardType == CardTypes.PASSIVE)
{
cardName = cardData.cardName;
cardDescription = cardData.cardDescription;
cardFlavour = cardData.cardFlavour;
}
Then the issue becomes when generating the card.
I think this would be handled by checking the list of cardsInDeck and calling for the prefab based on cardType.
Understanding that I think this is how I would check the type
private void GenerateCards()
{
foreach (Card card in avaliableCardsInDeck)
{
if (cardType = Plant)
{
CardController newCard = Instantiate(PlantCardPrefab, player1Hand);
newCard.transform.localPosition = Vector3.zero;
newCard.Initialize(card,0);
}
}
IDK. This coding thing is hard aye. Hahaha
Any idea’s, pointers? How should I go about this?
Thanks