When I press the button to answer the question, but don’t go to the next question, where’s what? Is there anyone who can help me?
This is the code of ImageAnswerButtons
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ImageAnswerButtons : MonoBehaviour
{
public GameObject answerAbackGreen; // Green is Correct;
public GameObject answerAbackRed; // Red is Wrong
public GameObject answerBbackGreen; // Green is Correct;
public GameObject answerBbackRed; // Red is Wrong
public GameObject answerCbackGreen; // Green is Correct;
public GameObject answerCbackRed; // Red is Wrong
public GameObject answerDbackGreen; // Green is Correct;
public GameObject answerDbackRed; // Red is Wrong
public GameObject answerA;
public GameObject answerB;
public GameObject answerC;
public GameObject answerD;
public AudioSource correctFx;
public AudioSource wrongFx;
public GameObject currentScore;
public int scoreValue;
void Update()
{
currentScore.GetComponent<TMPro.TMP_Text>().text = "SCORE: " + scoreValue;
}
public void AnswerA()
{
if (ImageQuestionGenerate.actualAnswer == "A")
{
answerAbackGreen.SetActive(true);
correctFx.Play();
scoreValue += 1;
}
else
{
answerAbackRed.SetActive(true);
wrongFx.Play();
}
answerA.GetComponent<Button>().enabled = false;
answerB.GetComponent<Button>().enabled = false;
answerC.GetComponent<Button>().enabled = false;
answerD.GetComponent<Button>().enabled = false;
StartCoroutine(NextQuestion());
}
public void AnswerB()
{
if (ImageQuestionGenerate.actualAnswer == "B")
{
answerBbackGreen.SetActive(true);
correctFx.Play();
scoreValue += 1;
}
else
{
answerBbackRed.SetActive(true);
wrongFx.Play();
}
answerA.GetComponent<Button>().enabled = false;
answerB.GetComponent<Button>().enabled = false;
answerC.GetComponent<Button>().enabled = false;
answerD.GetComponent<Button>().enabled = false;
StartCoroutine(NextQuestion());
}
public void AnswerC()
{
if (ImageQuestionGenerate.actualAnswer == "C")
{
answerCbackGreen.SetActive(true);
correctFx.Play();
}
else
{
answerCbackRed.SetActive(true);
wrongFx.Play();
}
answerA.GetComponent<Button>().enabled = false;
answerB.GetComponent<Button>().enabled = false;
answerC.GetComponent<Button>().enabled = false;
answerD.GetComponent<Button>().enabled = false;
StartCoroutine(NextQuestion());
}
public void AnswerD()
{
if (ImageQuestionGenerate.actualAnswer == "D")
{
answerDbackGreen.SetActive(true);
correctFx.Play();
scoreValue += 1;
}
else
{
answerDbackRed.SetActive(true);
wrongFx.Play();
}
answerA.GetComponent<Button>().enabled = false;
answerB.GetComponent<Button>().enabled = false;
answerC.GetComponent<Button>().enabled = false;
answerD.GetComponent<Button>().enabled = false;
StartCoroutine(NextQuestion());
}
IEnumerator NextQuestion()
{
yield return new WaitForSeconds(2);
answerAbackGreen.SetActive(false);
answerBbackGreen.SetActive(false);
answerCbackGreen.SetActive(false);
answerDbackGreen.SetActive(false);
answerAbackRed.SetActive(false);
answerBbackRed.SetActive(false);
answerCbackRed.SetActive(false);
answerDbackRed.SetActive(false);
answerA.GetComponent<Button>().enabled = true;
answerB.GetComponent<Button>().enabled = true;
answerC.GetComponent<Button>().enabled = true;
answerD.GetComponent<Button>().enabled = true;
ImageQuestionGenerate.displayingQuestion = false;
}
}
This is the code of ImageQuestionGenerate
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ImageQuestionGenerate : MonoBehaviour
{
public static string actualAnswer;
public static bool displayingQuestion = false;
public int questionNumber;
public ImageDisplay imageDisplay;
// ประกาศตัวแปรสำหรับเก็บคำถามแบบทายภาพและตัวเลือก
public Sprite questionSprite1;
public Sprite questionSprite2;
public string answerA1;
public string answerB1;
public string answerC1;
public string answerD1;
public string answerA2;
public string answerB2;
public string answerC2;
public string answerD2;
void Update()
{
if(displayingQuestion == false)
{
displayingQuestion = true;
questionNumber = Random.Range(1, 3);
if (questionNumber == 1)
{
// ใช้คำถามและตัวเลือกจากตัวแปรใหม่ที่ประกาศ
ImageDisplay.newQuestionSprite = questionSprite1;
ImageDisplay.newA = "ทดสอบ1";
ImageDisplay.newB = "ทดสอบ2";
ImageDisplay.newC = "ทดสอบ3";
ImageDisplay.newD = "ทดสอบ4";
actualAnswer = "A";
}
if (questionNumber == 2)
{
// ใช้คำถามและตัวเลือกจากตัวแปรใหม่ที่ประกาศ
ImageDisplay.newQuestionSprite = questionSprite2;
ImageDisplay.newA = "ทดสอบ1";
ImageDisplay.newB = "ทดสอบ2";
ImageDisplay.newC = "ทดสอบ3";
ImageDisplay.newD = "ทดสอบ4";
actualAnswer = "D";
}
ImageDisplay.pleaseUpdate = false;
}
}
}
This is the code of ImageDisplay
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ImageDisplay : MonoBehaviour
{
public ImageQuestionGenerate questionGenerate;
public GameObject screenQuestion;
public GameObject answerA;
public GameObject answerB;
public GameObject answerC;
public GameObject answerD;
public static Sprite newQuestionSprite; // แก้ไขเป็น Sprite สำหรับคำถามแบบทายภาพ
public static string newA;
public static string newB;
public static string newC;
public static string newD;
public static bool pleaseUpdate = false;
void Update()
{
if (pleaseUpdate == false)
{
pleaseUpdate = true;
StartCoroutine(PushTextOnScreen());
}
}
IEnumerator PushTextOnScreen()
{
yield return new WaitForSeconds(0.25f);
// เซ็ตภาพใน Image ของ GameObject screenQuestion
screenQuestion.GetComponent<Image>().sprite = newQuestionSprite;
answerA.GetComponent<TMPro.TMP_Text>().text = newA;
answerB.GetComponent<TMPro.TMP_Text>().text = newB;
answerC.GetComponent<TMPro.TMP_Text>().text = newC;
answerD.GetComponent<TMPro.TMP_Text>().text = newD;
}
}
And there’s also Assets\Scripts\Imagescripts\ImageDisplay.cs(50,35): error CS1061: ‘ImageQuestionGenerate’ does not contain a definition for ‘SomeMethod’ and no accessible extension method ‘SomeMethod’ accepting a first argument of type ‘ImageQuestionGenerate’ could be found (are you missing a using directive or an assembly reference?)
This is the screen I made.