I need some help with a fighting card game I’m developing. So far in the game, the player has access to a hand that holds 6 cards and a tabletop where they can present the card of their choice. Currently with the tabletop, you can add all of your cards into it, when I only want the player to be able to place one for every turn. I have an idea on how to write the script to prevent this from happening, but I’m a bit of a newbie to programming so I decided to reach out for help.
This is what I have so far:
if (this.transform.childCount > 1)
//if the tabletop top has a card gameObject on it, then don't add another one
I tried to keep this question short to fix my mistake in asking for last time, so I’m sorry if I went too vague. Let me know if there is any information you need and I’ll be happy to oblige.
That would technically run once per frame which is inefficient. Have you considered trying some other kind of implementation? I don’t exactly know how you are doing all of this but something like this might work.
public class TableTop : MonoBehaviour
// maybe you want to know whos turn it is.
public int activePlayer;
// the maximum amount of cards that can be played this turn
public int maximumPlayableCards;
// keep track of how many cards the active player has placed on the table
public int activePlayerCardsPlacedOnTable;
private void PlaceCardOnTable()
if (activePlayerCardsPlacedOnTable < maximumPlayableCards)
// let them place the card and then increment activePlayerCardsPlacedOnTable by 1
private void EndActiveCardPlacementPhase()
// do something when the player has placed their card
activePlayer = 2; // now it's player 2's turn to place a card?
maximumPlayableCards = 1; // they can place 1 card
activePlayerCardsPlacedOnTable = 0; // they have not placed any cards yet