0

I've created a simple 2d game like a questionnaire where in there are 3 choices. obviously only 1 button carries the answer. all 3 buttons are sharing the same script for changing scene (scene 0). which is fine.

now i need to detect if the user used the Correct button for the answer, (let's say A is the correct button). it should still change the screen back to 0 and add the corresponding points to the Score Counter.

how do i use an if statement to check which among the 3 buttons is pressed for the correct answer so that Scorecount++; ... What i have in mind is a separate Script to detect if the Selection is correct or not but i'm not sure how to start.

Thanks all.

Right now i'm trying to reference each button, but i'm not sure how to put the Onclick even as a conditional statement to check if buttonA (correct answer) was selected.

public Button buttonA;
public Button buttonB;
public Button buttonC;

void checkAnswer()

{
    buttonA = GameObject.Find("btnA").GetComponent<Button>();
    buttonB = GameObject.Find("btnB").GetComponent<Button>();
    buttonC = GameObject.Find("btnC").GetComponent<Button>();




}
wh3resmycar2
  • 191
  • 1
  • 13
  • ***2**.Button Component* is exactly what you are looking for in the answer from the duplicated question. – Programmer Mar 19 '17 at 12:28
  • ok so how do i reference the buttons on my Scene? they are called btnA btnB and btnC. – wh3resmycar2 Mar 19 '17 at 12:34
  • Like you did in your question. You need to put that in the `OnEnable` function before all the `button1.onClick.AddListener(() => buttonCallBack(button1));` calls. – Programmer Mar 19 '17 at 12:37

0 Answers0