Can you share some unity card game script example?
Hi !!
I have got the point of your interest. the program can be highly run in c# language .The following code is used for creating a
card game.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
Â
public class DeckOfCards : MonoBehaviour
{
   public List<GameObject> deck = new List<GameObject>();
Â
   private List<GameObject> cards = new List<GameObject>();
   private List<GameObject> hand = new List<GameObject>();
   private int cardsDealt = 0;
   private bool showReset = false;
Â
   void ResetDeck()
   {
      cardsDealt = 0;
      for (int i = 0; i < hand.Count; i++) {
        Destroy(hand[i]);
      }
       hand.Clear();
       cards.Clear();
       cards.AddRange(deck);
      showReset = false;
   }
Â
   GameObject DealCard()
   {
       if(cards.Count == 0)
       {
        showReset = true;
        return null;
           //Alternatively to auto reset the deck:
           //ResetDeck();
       }
Â
       int card = Random.Range(0, cards.Count – 1);
       GameObject go = GameObject.Instantiate(cards[card]) as GameObject;
       cards.RemoveAt(card);
Â
      if(cards.Count == 0) {
        showReset = true;
      }
Â
       return go;
   }
Â
   void Start()
   {
       ResetDeck();
   }
Â
   void GameOver()
   {
      cardsDealt = 0;
      for (int v = 0; v < hand.Count; v++) {
        Destroy(hand[v]);
      }
       hand.Clear();
       cards.Clear();
       cards.AddRange(deck);
   }
Â
   void OnGUI()
   {
      if (!showReset) {
        // Deal button
           if (GUI.Button(new Rect(10, 10, 100, 20), "Deal"))
        {
         MoveDealtCard();
        }
      }
      else {
        // Reset button
           if (GUI.Button(new Rect(10, 10, 100, 20), "Reset"))
        {
         ResetDeck();
        }
      }
      // GameOver button
       if (GUI.Button(new Rect(Screen.width – 110, 10, 100, 20), "GameOver"))
      {
        GameOver();
      }
   }
Â
   void MoveDealtCard()
   {
       GameObject newCard = DealCard();
      // check card is null or not
      if (newCard == null) {
        Debug.Log("Out of Cards");
        showReset = true;
        return;
      }
Â
      //newCard.transform.position = Vector3.zero;
      newCard.transform.position = new Vector3((float)cardsDealt / 4, (float)cardsDealt / -4, (float)cardsDealt / -4); // place card 1/4 up on all axis from last
      hand.Add(newCard);
      cardsDealt ++;
   }
}
Â
Thanks
Nowell