Reload question generator each time button pressed
Hey, so i have a button which i press in my game which fires up a question generator quiz for the player to answer, and if they get it right they activate another button for single usage as an attack(if they get it wrong they miss a go)...if they answer questions correctly they earn the one off attack option..
...but it seems once i've done this once i can't then load the questions up again, i've tried calling it as a prefab, tried making it just inactive then active each time, tried restarting the script attached to it each time...no such luck...any ideas? Should i set the question generator as a separate scene which is called and then unloaded each time? but if that's the case would that then delete my current scene and also affect performance?
Hello there.
you are doing something wrong. But we need to se screenshots and code to know what. Do NOT need diferent scenes at all.
What you mean with can't then load the questions up again? You need to talk correctly. Its a Canvas? Its a Camera? its a Scene GameObject...? What.
below are the two main scripts for this...any help would be super appreciated and i'll have to credit you when i finally finish this :)
Battle System - when attack button pressed - launches game controller which launches $$anonymous$$i quiz (i've skipped the non relevant parts otherwise it makes it too long)
//must answer questions to use attack
public void OnAttackButton()
{
if (state != BattleState.PLAYERTURN)
return;
// quizCentre.SetActive(true); // (possibly solution 1)
Instantiate(quizPrefab); //(possible solution 2)
}
``` public void WonRound() { realAttackButton.SetActive(true); fakeAttackButton.SetActive(false); //*** Destroy(gameController); }
//real attack button launches this method public void OnAttackEarnt() { StartCoroutine(PlayerAttack()); realAttackButton.SetActive(false); fakeAttackButton.SetActive(true); //gameController.enabled = false; //toggle this script to re-invoke it //gameController.enabled = true; //toggle this script to re-invoke it } } ```
game controller script: (again i've removed the non relevant parts to this issue)
``` public BattleSystem BattleScript; // public GameObject questionDisplay; // public GameObject roundEndDisplay; ``` public void AnswerButtonClicked(bool isCorrect) { if (isCorrect) { playerScore += currentRoundData.pointsAddedForCorrectAnswer;
// If the AnswerButton that was clicked was the correct answer, add points scoreDisplay.text = playerScore.ToString(); } else { LoseAttack(); } if (questionPool.Length > questionIndex + 1) // If there are more questions, show the next question { questionIndex++; ShowQuestion(); } else // If there are no more questions, the round ends { EarnAttack(); } }
//run the attack enemy routine
public void EarnAttack()
{
isRoundActive = false;
dataController.SubmitNewPlayerScore(playerScore);
BattleScript.WonRound();
}
// end questions, update score and skip go so enemy can now attack you
public void LoseAttack()
{
isRoundActive = false;
dataController.SubmitNewPlayerScore(playerScore);
// questionDisplay.SetActive(false);
BattleScript.SkipGo();
}
Your answer
Follow this Question
Related Questions
Win condition for both players being on a separate specific positions? 0 Answers
Vector2.up stops working after jumping a few times? 0 Answers
Quiz game - How to go about allowing users to input their own questions. 1 Answer
please help me. i want to make simillar game like Snotput. the link is given below. 0 Answers