2016-12-26 71 views
0

我有這些錯誤,我不理解試圖固定我的自我,但我仍然在學習的團結錯誤在Unity

Errors

在我的代碼

卡。 CS

using UnityEngine; 
using UnityEngine.UI; 
using System.Collections; 

public class Card : MonoBehaviour { 

    public static bool DO_NOT = false; 

    [SerializeField] 
    private int state; 

    [SerializeField] 
    private int cardValue; 

    [SerializeField] 
    private bool initialized = false; 

    private Sprite cardBack; 
    private Sprite cardFace; 

    private GameObject manager; 

    void start() { 
     state = 0; 
     manager = GameObject.FindGameObjectsWithTag ("Manager"); 

    } 

    public void setupGrapgics() { 

     cardBack = manager.GetComponents<GameManager>().getCardBack(); 
     cardFace = manager.GetComponents<GameManager>().getCardFace (cardValue); 

     flipCard(); 

    } 

    void flipCard() { 

     if(state == 0 && !DO_NOT) 
      GetComponent<Image>().sprite = cardBack; 
     else if (state == 1 && !DO_NOT) 
      GetComponent<Image>().sprite = cardFace; 

    } 

    public int CardValue { 

     get { return cardValue;} 
     set { cardValue = value; } 

    } 

    public int State { 

     get { return state; } 
     set { state = value; } 
    } 

    public bool Initialized { 

     get { return initialized; } 
     set { Initialized = value; } 

    } 

    public void falseCheck(){ 

     StartCoroutine (pause()); 

    } 

    IEnumerator pause() { 

    yield return new WaitForSeconds (1); 
    if (state == 0) 
     GetComponent<Image>().sprite = cardBack; 
    else if (state == 1) 
     GetComponent<Image>().sprite = cardFace; 
    DO_NOT = false; 

    } 
} 

回答

0

這個錯誤是因爲 「FindGameObjectsWithTag」(返回[]),變化爲 「FindGameObjectWithTag」

0

第一個錯誤是因爲方法GameObject.FindGameObjectsWithTag ("Manager");返回一個數組,並且您嘗試將該數組分配給非數組類型。你應該使用GameObject.FindGameObjectWithTag("Manager");(注意,在Object中不是's'),它只返回匹配標籤的第一個GameObject。

最後兩個錯誤與第一個有些相關,因爲它們也返回數組。行manager.GetComponents<GameManager>()返回組件的數組。要僅返回給定類型的第一個組件,請使用manager.GetComponent<GameManager>()