I have these Error That I'm not understanding tried to fixed my self but I'm still learning unity
Under I have the code
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;
}
}
此错误是因为“ FindGameObjectsWithTag”(返回[]),更改为“ FindGameObjectWithTag”
The first error is because the method GameObject.FindGameObjectsWithTag ("Manager");
returns an array and you attempt to assign the array to a non-array type. You should instead use GameObject.FindGameObjectWithTag("Manager");
(note, no 's' in Object), which returns only the first GameObject that matches the tag.
The last two errors are related somewhat to the first, since they also return arrays. The line manager.GetComponents<GameManager> ()
return arrays of components. To only return the first component of the given type, use manager.GetComponent<GameManager>()
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.