Search Unity

How can I dsplay which cards are shuffled onto the scene?

Discussion in 'Scripting' started by Josenifftodd, May 27, 2015.

  1. Josenifftodd

    Josenifftodd

    Joined:
    Nov 29, 2013
    Posts:
    158
    How can I display which cards are shuffled onto the scene and then change their position to each of the players hands?

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4.  
    5. public class PlayersHand : MonoBehaviour {
    6.     public List<GameObject> deck = new List<GameObject>();
    7.     public List<GameObject> playerhand = new List<GameObject>();
    8.     public List<GameObject> oponentshand = new List<GameObject>();
    9.     public GameObject SpawnSpot;
    10.  
    11.  
    12.  
    13.  
    14.     // Use this for initialization
    15.     void Start () {
    16.         ShuffleCards ();
    17.         AddCards ();
    18.  
    19.     }
    20.     // Update is called once per frame
    21.     void Update () {
    22.            
    23.     }
    24.  
    25.     public void ShuffleCards () {
    26.         GameObject Deck = GameObject.Find("Deck");
    27.  
    28.             for(int i=0;i<52;i++){
    29.                 int prefabIndex = UnityEngine.Random.Range(0,deck.Count -1);
    30.                 GameObject go = Instantiate(deck[prefabIndex], new Vector3 (0,0,0), Quaternion.identity) as GameObject;
    31.                 go.transform.parent = Deck.transform;
    32.                 go.transform.position = SpawnSpot.transform.position;
    33.             }
    34.     }
    35.  
    36.  
    37.     void AddCards () {
    38.         // Player 1 Cards
    39.         playerhand.Add (deck [1]);
    40.         playerhand.Add (deck [3]);
    41.         playerhand.Add (deck [5]);
    42.         playerhand.Add (deck [7]);
    43.         playerhand.Add (deck [9]);
    44.         playerhand.Add (deck [11]);
    45.         // Player 2 Cards
    46.         oponentshand.Add (deck [2]);
    47.         oponentshand.Add (deck [4]);
    48.         oponentshand.Add (deck [6]);
    49.         oponentshand.Add (deck [8]);
    50.         oponentshand.Add (deck [10]);
    51.         oponentshand.Add (deck [12]);
    52.  
    53.     }
    54. }
    55.