public void addToPile() { GameScript gameScript = FindObjectOfType <Camera>().GetComponent <GameScript>(); pile.Add(gameScript.getCardSelected()); if (pile.Count > 1) { GameObject newObj; GameObject createdObj; Transform parent = gameObject.transform.parent; if (gameObject.name.Contains("LH")) { newObj = Resources.Load <GameObject>("LPiledCard"); //parentName = "LHCanvas" + houseNum; createdObj = Instantiate(newObj, parent); createdObj.name = "LH" + houseNum + "C" + (pile.Count - 1); createdObj.transform.localPosition = new Vector3((pile.Count - 2) * -15.0f, 0.0f, 0.0f); } else //if (gameObject.name.Contains("RH")) { newObj = Resources.Load <GameObject>("RPiledCard"); createdObj = Instantiate(newObj, parent); createdObj.name = "RH" + houseNum + "C" + (pile.Count - 1); createdObj.transform.localPosition = new Vector3((pile.Count - 2) * 15.0f, 0.0f, 0.0f); } gameObject.transform.SetSiblingIndex(pile.Count - 1); PiledScript piledScript = createdObj.GetComponent <PiledScript>(); piledScript.setCard(pile[pile.Count - 2]); piledScript.loadCard(); } if (gameScript.getCardSelObjName().Contains("Card")) { CardScript cardScript = GameObject.Find(gameScript.getCardSelObjName()).GetComponent <CardScript>(); DeckScript deckScript = GameObject.Find("P" + gameScript.getPlayer() + " Deck").GetComponent <DeckScript>(); TrashScript trashScript = GameObject.Find("P" + gameScript.getPlayer() + " Trash").GetComponent <TrashScript>(); deckScript.removeCard(); cardScript.setEnabled(false); cardScript.selectCard(); //To unselect it if (trashScript.isEmpty() && deckScript.isEmpty()) { Instantiate(Resources.Load <GameObject>("Winner"), GameObject.Find("Canvas").transform); GameObject.Find("Winner").GetComponent <Text>().text = "Player " + gameScript.getPlayer() + " wins!!"; } } else if (gameScript.getCardSelObjName().Contains("Trash")) { TrashScript trashScript = GameObject.Find(gameScript.getCardSelObjName()).GetComponent <TrashScript>(); trashScript.removeCard(); gameScript.setCardSelected(null); gameScript.setCardSelObjName(null); DeckScript deckScript = GameObject.Find("P" + gameScript.getPlayer() + " Deck").GetComponent <DeckScript>(); if (trashScript.isEmpty() && deckScript.isEmpty()) { Instantiate(Resources.Load <GameObject>("Winner"), GameObject.Find("Canvas").transform); GameObject.Find("Winner(Clone)").GetComponent <Text>().text = "Player " + gameScript.getPlayer() + " wins!!"; } } else if (gameScript.getCardSelObjName().Contains("Main")) { HouseScript houseScript = GameObject.Find(gameScript.getCardSelObjName()).GetComponent <HouseScript>(); houseScript.removeCard(); gameScript.setCardSelected(null); gameScript.setCardSelObjName(null); } loadCard(); }
public void drawCard() { GameScript gameScript = FindObjectOfType <Camera>().GetComponent <GameScript>(); GameObject trashObj = GameObject.Find("P" + gameScript.getPlayer() + " Trash"); TrashScript trashScript = trashObj.GetComponent <TrashScript>(); string objName = "P" + gameScript.getPlayer() + " Deck"; if (gameObject.name.CompareTo(objName) == 0 && (gameScript.noEmptyHouses() || trashScript.isEmpty())) { // if it's empty we must pull the cards from trash if (cardDeck.Count == 0) { cardDeck = trashScript.getTrashDeck(); trashScript.emptyTrash(); this.GetComponent <Image>().sprite = Resources.Load <Sprite>("Images/deck"); } cardObject = GameObject.Find("P" + gameScript.getPlayer() + " Card"); CardScript cardScript = cardObject.GetComponent <CardScript>(); cardScript.setCard(cardDeck[0]); cardScript.loadCard(); cardObject.GetComponent <Image>().enabled = true; cardObject.GetComponentInChildren <Text>().enabled = true; if (cardDeck.Count == 1) // if this is the last card being drawn { this.GetComponent <Image>().sprite = Resources.Load <Sprite>("Images/empty"); } } }