Beispiel #1
0
    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();
    }