void Stack(GameObject selected) { // if empty bottom stack the cards in place // else stack the cards with a negative y offset DeckSelectable s1 = slot1.GetComponent <DeckSelectable>(); DeckSelectable s2 = selected.GetComponent <DeckSelectable>(); float yOffset = 0; slot1.transform.position = new Vector3(selected.transform.position.x, selected.transform.position.y - yOffset, selected.transform.position.z - 0.01f); slot1.transform.parent = selected.transform; // this makes the children move with the parents if (s1.inDeckPile) // removes the cards from the top pile to prevent duplicate cards { DeckFunct.tripsOnDisplay.Remove(slot1.name); } else if (s1.top) // keeps track of the current value of the top decks as a card has been removed { DeckFunct.topPos[s1.row].GetComponent <DeckSelectable>().value = s1.value - 1; } else // removes the card string from the appropriate bottom list { DeckFunct.bottoms[s1.row].Remove(slot1.name); } s1.inDeckPile = false; // you cannot add cards to the trips pile so this is always fine s1.row = s2.row; }
// Start is called before the first frame update void Start() { List <string> deck = DeckFunction.GenerateDeck(); DeckFunct = FindObjectOfType <DeckFunction>(); userInput = FindObjectOfType <DeckUserInput>(); int i = 0; foreach (string card in deck) { if (this.name == card) { cardFace = DeckFunct.cardFaces[i]; break; } i++; } spriteRenderer = GetComponent <SpriteRenderer>(); selectable = GetComponent <DeckSelectable>(); }