Hi guys,
I am basically trying to execute code after I click on a correct answer (that I assigned to first answer in list). However the code executes right at the start, not when I click on the answer.
I think I do understand why it is doing that, my question is how else should I approach this ? It feels so simple and yet I have been stuck on it for quite some time. How would I execute the code after clicking on the correct answer? Any ideas? Thanks a lot in advance… here is a code > (btw I have a canvas with buttons on which I loaded the list)
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
public class QuizLearning : MonoBehaviour {
public List <string> QnA = new List <string>();
public GameObject parentCanvas;
public int correctAnswer;
void Start ()
{
QnA.Add ("Where is Rome?");
QnA.Add ("Italy");
QnA.Add ("France");
QnA.Add ("Spain");
QnA.Add ("Norway");
AddText ();
QnA [1] = correctAnswer.ToString (); // italy equals correct answer
OnMouseDown (correctAnswer); // i want to call a method that will execute code` after I click on "italy" button
}
void AddText ()
{
int i = 0;
foreach (Text t in parentCanvas.GetComponentsInChildren<Text>())
{
t.text = QnA*;*
-
i++;*
-
// this just loads the list on buttons*
-
}*
}
-
void OnMouseDown (int answerCorrect)*
-
{*
-
parentCanvas.gameObject.SetActive (false);*
-
Debug.Log("whatever");*
// I want this code to execute AFTER I click on “italy” button, but it executes right at the start
- }*
}