Unity CS1001:需要标识符,但所有语法都正确吗?
Unity CS1001: Identifier expected but all syntax is right?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class QuizManager : MonoBehaviour
{
public List<QuestionsAndAnswers> QnA;
public GameObject[] options;
public int currentQuestion;
private Text QuestionTxt;
private void start()
{
generateQuestion();
}
void SetAnswers()
{
for (int i = 0; i < options.Length; i++)
{
options[i].transform.GetChild(0).GetComponent<Text>().text = QnA[currentQuestion].Answers.[i];
}
}
void generateQuestion()
{
currentQuestion = Random.Range(0, QnA.Count);
QuestionTxt.text = QnA[currentQuestion].Question;
}
}
我找不到问题!我知道问题出在第 23 行 (options[i].transform.GetChild(0).GetComponent<Text>().text = QnA[currentQuestion].Answers.[i];
)。它在期待什么,但我不知道是什么。浏览网页没有帮助。
冷是行尾的点吗?但是我不知道 Answers 的数据类型。
// yours
options[i].transform.GetChild(0).GetComponent<Text>().text = QnA[currentQuestion].Answers.[i];
// new
options[i].transform.GetChild(0).GetComponent<Text>().text = QnA[currentQuestion].Answers[i];
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class QuizManager : MonoBehaviour
{
public List<QuestionsAndAnswers> QnA;
public GameObject[] options;
public int currentQuestion;
private Text QuestionTxt;
private void start()
{
generateQuestion();
}
void SetAnswers()
{
for (int i = 0; i < options.Length; i++)
{
options[i].transform.GetChild(0).GetComponent<Text>().text = QnA[currentQuestion].Answers.[i];
}
}
void generateQuestion()
{
currentQuestion = Random.Range(0, QnA.Count);
QuestionTxt.text = QnA[currentQuestion].Question;
}
}
我找不到问题!我知道问题出在第 23 行 (options[i].transform.GetChild(0).GetComponent<Text>().text = QnA[currentQuestion].Answers.[i];
)。它在期待什么,但我不知道是什么。浏览网页没有帮助。
冷是行尾的点吗?但是我不知道 Answers 的数据类型。
// yours
options[i].transform.GetChild(0).GetComponent<Text>().text = QnA[currentQuestion].Answers.[i];
// new
options[i].transform.GetChild(0).GetComponent<Text>().text = QnA[currentQuestion].Answers[i];