起初它是文本,但我希望它是图像/精灵,所以我将其更改为对象。但是现在我得到了这些错误。我的错误在第50行和第51行。
请帮助:(
错误:无法将索引应用于类型为object的表达式
错误:分配的左侧必须是变量,属性或 索引器
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Kuis : MonoBehaviour {
[SerializeField] Text teksPertanyaan;
[SerializeField] Object[] teksPilihan;
[SerializeField] Soal[] soal;
[SerializeField] int indeksSoal;
//deklarasi lcm
int a, b, m, x, hasil;
// Use this for initialization
void Start () {
a = 4;
b = 5;
m = 9;
x = 0;
for (int i = 0; i < soal.Length; i++) {
x = (a * x + b) % m;
hasil = x % 3;
Debug.Log("" +hasil);
tampilSoal (hasil);
}
}
// Update is called once per frame
void Update () {
}
IEnumerator dealay(){
yield return new WaitForSeconds (1);
//tampilSoal (Random.Range (1, 5));
tampilSoal (Random.Range (0, soal.Length));
//Debug.Log("" +hasil);
Debug.Log("" +indeksSoal);
}
public void konten(){
StartCoroutine (dealay ());
}
void tampilSoal(int _indeksSoal){
indeksSoal = _indeksSoal;
teksPertanyaan.text = soal [_indeksSoal].pertanyaan;
for (int i = 0; i < soal [_indeksSoal].pilihan.Length; i++) {
teksPilihan [i].ToString = soal [_indeksSoal].pilihan [i];
}
}
public void verifikasiJawaban(int _indeksJawaban){
if (_indeksJawaban == soal [indeksSoal].indeksJawaban) {
print ("Jawaban Benar!");
konten ();
}
else {
//hilangSoal.SetActive (false);
print ("Jawaban Salah!");
konten ();
}
}
}