Skip to content

Instantly share code, notes, and snippets.

@ARoomWithABue
Created November 27, 2018 18:54
Show Gist options
  • Save ARoomWithABue/72c8e0a9425593a212119c6bc5870e1a to your computer and use it in GitHub Desktop.
Save ARoomWithABue/72c8e0a9425593a212119c6bc5870e1a to your computer and use it in GitHub Desktop.
Basic ManagedBehaviour Use
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