1
\$\begingroup\$

I have thirty (30) buttons in a trivia game, they are laid out in the following configuration with three rows:

( A, B, C, D, E, F, G, H, I, J)
( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
(00,01,02,03,04,05,06,07,08,09)

Using these combinations of buttons and clicking one and only one from each row I have a thousand (1000) - three (3) button combinations. E.g.: A27 would be one combination of the thousand possibilities. These are not random combinations each opens a very specific scene.

What I am trying to do is create a C# script that when I click any of these three (3) button combinations it will open a new scene. Once that scene is open I’m okay because then have my own scripts attached to the single buttons in the new scene to continue to a further scene.

What I can’t figure out is the syntax, should I use if Statements such as - if (Btn_A) && (Btn_1) && (Btn_01) then load scene such and such? Then do I attach the script to the canvas then to each of the three button combinations (A 1000 Scripts combinations)?

\$\endgroup\$
3
  • 1
    \$\begingroup\$ it is a bit unclear what you're asking. Do you mean that you got 1000 scenes? And then you want your script to open one of those scenes depending on which combination is pressed? \$\endgroup\$
    – Leggy7
    Jul 29, 2016 at 20:32
  • \$\begingroup\$ @Leggy7 Edit: I think he actually means he has 1000 scenes. \$\endgroup\$ Jul 29, 2016 at 22:25
  • \$\begingroup\$ Yeah, 10^3 possible combinations, 10 buttons per row and three choices. \$\endgroup\$
    – House
    Jul 29, 2016 at 23:34

1 Answer 1

4
\$\begingroup\$

You should not try to hardcode the combinations. Seems fairly straightforward to name your scenes A207, or F409, and so on. When the button combination is entered, simply load the scene with the name produced.

string button1 = selectedButtonA.text;
string button2 = selectedButtonB.text;
string button3 = selectedButtonC.text;
string name = button1 + button2 + button3;

SceneManager.LoadScene(name);

This code executes in a script attached to the canvas object or some kind of manager object. Each row of buttons has a script that sets the selected button values. i.e. the first row buttons, when selected, will assign themselves to selectedButtonA in the scene loading script.

\$\endgroup\$
2
  • \$\begingroup\$ Clever solution. \$\endgroup\$ Jul 29, 2016 at 22:26
  • \$\begingroup\$ Thank you I will try this and I'm sure it will work for me. \$\endgroup\$ Jul 31, 2016 at 13:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .