How Can I put a Dialogue of each Questions in the inspector?
How Can I put a Dialogue of each Questions in the inspector? I want to Start the Dialogue box first after the Questions, I don't know how can I trigger each of the Dialogues in the Question
I have a Script
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.SceneManagement;
public class GameController : MonoBehaviour { public Text ScoreDisplay; public Text TimeRemainingDisplay; public Text questionText; public SimpleObjtPool answwerButtonPool; public Transform answerButtonParent; public GameObject questionDisplay; public GameObject RoundOverPanel;
private DataControl dataControl;
private RoundData currentData;
private QuestionData[] questionPool;
private QuestionData dialogueSentences;
private bool isRoundActive;
private float timeRemaining;
private int questionIndex;
private int playerScore;
private List<GameObject> answerButtonObjects = new List<GameObject>();
public void StartQuestion()
{
dataControl = FindObjectOfType<DataControl>();
currentData = dataControl.GetCurrnetData();
questionPool = currentData.questions;
timeRemaining = currentData.timeSeconds;
UpdateTimeRemaining();
playerScore = 0;
ShowQuestion();
isRoundActive = true;
}
private void ShowQuestion()
{
RemoveQuestionButton();
QuestionData questionData = questionPool[questionIndex];
questionText.text = questionData.questionText;
for (int i = 0; i < questionData.answers.Length; i++)
{
GameObject answerButtonGameObject = answwerButtonPool.GetObject();
answerButtonGameObject.transform.SetParent(answerButtonParent);
answerButtonObjects.Add(answerButtonGameObject);
AnswerButton answerButton = answerButtonGameObject.GetComponent<AnswerButton>();
answerButton.Setup(questionData.answers[i]);
}
}
private void RemoveQuestionButton()
{
while (answerButtonObjects.Count > 0)
{
answwerButtonPool.RetrunObject(answerButtonObjects[0]);
answerButtonObjects.RemoveAt(0);
}
}
public void AnswerButtonClick(bool isCorrect) // answer button will automatically place in the question
{
if (isCorrect)
{
playerScore += currentData.Scorring;
ScoreDisplay.text = "Score: " + playerScore.ToString();
}
if (questionPool.Length > questionIndex + 1)
{
questionIndex++;
ShowQuestion();
}
else
{
EndRound();
}
}
public void EndRound()
{
isRoundActive = true;
questionDisplay.SetActive(false);
RoundOverPanel.SetActive(true);
}
void Update() // every frame the time value will decrease
{
if (isRoundActive)
{
timeRemaining -= Time.deltaTime;
UpdateTimeRemaining();
if (timeRemaining <= 0f)
{
EndRound();
}
}
}
public void UpdateTimeRemaining()
{
TimeRemainingDisplay.text = "Time: " + Mathf.Round(timeRemaining).ToString();
}
}
Your answer
Follow this Question
Related Questions
Animate Text letter by letter 3 Answers
Animate a count | how to make a count to grow smoothly ? 1 Answer
Creating multiple text components on a canvas 1 Answer
How do I keep child gameobject of UI text 1 Answer
GUI/Text Asset for Unity? 0 Answers