我有这些错误我不理解试图修复自己,但我还在学习团结
我有代码
Card.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 :(得分:0)
这个错误是因为“FindGameObjectsWithTag”(return []),改为“FindGameObjectWithTag”
答案 1 :(得分:0)
第一个错误是因为方法GameObject.FindGameObjectsWithTag ("Manager");
返回一个数组,并且您尝试将该数组分配给非数组类型。您应该使用GameObject.FindGameObjectWithTag("Manager");
(注意,在对象中没有&#39; s),它只返回与标记匹配的第一个GameObject。
最后两个错误与第一个错误有关,因为它们也返回数组。行manager.GetComponents<GameManager> ()
返回组件数组。要仅返回给定类型的第一个组件,请使用manager.GetComponent<GameManager>()
。