Esempio n. 1
0
    void AddNewCard(CardPattern cardPattern, int positionIndex)
    {
        GameObject card = Instantiate(Resources.Load <GameObject>("Prefabs/牌")); //Instantiate 產生一個物件,從resources讀取"牌"

        card.GetComponent <Card>().cardPattern = cardPattern;                    //取得Card腳本中的cardPattern
        card.name = "牌_" + cardPattern.ToString();                               //改名稱
        card.transform.position = positions[positionIndex].position;

        GameObject graphic = Instantiate(Resources.Load <GameObject>("Prefabs/圖")); //Instantiate 產生一個物件,從resources讀取"圖"

        graphic.GetComponent <SpriteRenderer>().sprite = Resources.Load <Sprite>("Graphics/Foods/" + cardPattern.ToString());
        graphic.transform.SetParent(card.transform);               //變成牌的子物件
        graphic.transform.localPosition = new Vector3(0, 0, 0.1f); //設定座標
        graphic.transform.eulerAngles   = new Vector3(0, 180, 0);  //順著Y軸轉180度 翻牌時不會左右顛倒
    }
Esempio n. 2
0
    void AddNewCards(CardPattern cardPattern, int positionIndex)
    {
        GameObject card = Instantiate(Resources.Load <GameObject>("Prefabs/card"));

        card.GetComponent <Card>().cardPattern = cardPattern;
        card.name = "card_" + cardPattern.ToString();
        card.transform.position = positions[positionIndex].position;

        GameObject CardGraph1 = Instantiate(Resources.Load <GameObject>("Prefabs/card1"));

        CardGraph1.GetComponent <SpriteRenderer>().sprite = Resources.Load <Sprite>("CardGraph/" + cardPattern.ToString());


        CardGraph1.transform.SetParent(card.transform);              //變反面(背牌)的子物件
        CardGraph1.transform.localPosition = new Vector3(0, 0, 0f);  //設定座標
        CardGraph1.transform.eulerAngles   = new Vector3(0, 180, 0); //順著Y軸轉
    }