I am making a quiz game in Unity. I want an animation to show a countdown. The animation is a 10 second long animation of dynamite stick, where the fuse gets shorter and shorter until the it explodes.
I want the animation to start over then the time is up and the question is changed (now the question changes automatic after 10 seconds) i also want the animation to start over when an answer is clicked and the new question shows up.
Here is my code:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
using System.Collections.Generic;
public class GameController : MonoBehaviour
{
public Animation DynamiteTimer;
public Animator DynamiteAnimator;
// Use this for initialization
void Start()
{
dataController = FindObjectOfType<DataController>();
currentRoundData = dataController.GetCurrentRoundData();
questionPool = currentRoundData.questions;
timeRemaining = currentRoundData.timeLimitInSeconds;
UpdateTimeRemainingDisplay();
playerScore = 0;
questionIndex = 0;
ShowQuestion();
//animation
//DynamiteTimer.Play();
//Image.StartPlayback();
isRoundActive = true;
}
//IEnumerator ShowQuestion()
private void ShowQuestion()
{
//yield return new WaitForSeconds(timeBetweenQuestions);
RemoveAnswerButtons();
//Choose question er her!!!!!!!!!!!!!!!!!!!!!
ChooseQuestion();
QuestionData questionData = questionPool[questionIndex];
questionDisplayText.text = questionData.questionText;
for (int i = 0; i < questionData.answers.Length; i++)
{
GameObject answerButtonGameObject = answerButtonObjectPool.GetObject();
answerButtonGameObjects.Add(answerButtonGameObject);
answerButtonGameObject.transform.SetParent(answerButtonParent);
AnswerButton answerButton = answerButtonGameObject.GetComponent<AnswerButton>();
answerButton.Setup(questionData.answers*);*
}
}
answerButtonObjectPool.ReturnObject(answerButtonGameObjects[0]);
answerButtonGameObjects.RemoveAt(0);
}
}
//public IEnumerator AnswerButtonClicked(bool isCorrect)
public void AnswerButtonClicked(bool isCorrect)
{
if (isCorrect)
{
playerScore += currentRoundData.pointsAddedForCorrectAnswer;
scoreDisplayText.text = "Score: " + playerScore.ToString();
//Mille kode:
correctAnswerPanel.SetActive(true);
questionDisplay.SetActive(false);
StartCoroutine(TimeBetweenQuestions());
DynamiteTimer.Play();
//DynamiteAnimator.Play();
}
else
{
//Mille kode:
falseAnswerPanel.SetActive(true);
questionDisplay.SetActive(false);
StartCoroutine(TimeBetweenQuestions());
DynamiteTimer.Play();
//DynamiteAnimator.Play()
}
//if (questionPool.Length > 0)
if (qNumber + 1 < questionPool.Length)
{
qNumber++;
ShowQuestion();
//DynamiteAnimator.SetTrigger(“Click”);
//DynamiteAnimator.StartPlayback();
//DynamiteTimer.Play();
}
else
{
//correctAnswerPanel.SetActive(false);
//falseAnswerPanel.SetActive(false);
EndRound();
}
}
(I have removed a lot of code, I didn’t think relevant for this question)
I have the animation set up under the gamecontroller object as well as the animation.
Up until thia point I followed the tutorial from Unity on how to make a quiz game.
Thank you in advance.