Created
November 27, 2018 18:54
-
-
Save ARoomWithABue/72c8e0a9425593a212119c6bc5870e1a to your computer and use it in GitHub Desktop.
Basic ManagedBehaviour Use
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class DeckManager : ManagedBehaviour<DeckManager> | |
{ | |
public Stack<CardData> _deck; | |
public GameObject prefab; | |
public Card Draw() | |
{ | |
var obj = Instantiate(prefab, new Vector3(1000f, 1000f, 0f), Quaternion.identity); | |
var card = obj.GetComponent<Card>(); | |
var data = _deck.Pop(); | |
card.Init(data.suit, data.cardNum); | |
return card; | |
} | |
public override void Init() | |
{ | |
_deck = new Stack<CardData>(); | |
char[] suits = { 'C', 'H', 'S', 'D' }; | |
foreach (var suit in suits) | |
{ | |
for (int i = 1; i <= 13; i++) | |
{ | |
_deck.Push(new CardData(suit, i)); | |
} | |
} | |
_deck = new Stack<CardData>(_deck.Shuffle()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment