Three button combination to open next scene
I have a heck of a problem. I have thirty (30) buttons in a proposed trivia game, they are laid out in the following configuration - top row (A,B,C,D,E,F,G,H,I,J, ) second row (0,1,2,3,4,5,6,7,8,9, and a third row which are numbered (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)? I have been trying to figure this out for two months (It’s Driving Me Nuts).
Hellllllllppppp!!!!
Answer by smnerat · Jul 31, 2016 at 05:12 AM
This is dependent on how you order your levels. You may need to change this around a bit on your own depending on how you want your levels loaded, but you can assign a value from 0 to 9 for each of the three rows, but do it as a string and not a number. So instead of 1 or 4, it would be "1" or "4". Then you can just add the strings together and convert it to an int.
For this example, I just put everything in Start(), but you would probably want to assign each variable on a button click and check in Update() if they are null or not. Once all three are assigned you can go ahead and create your levelID and load the next scene.
private string s1;
private string s2;
private string s3;
void Start () {
s1 = "3"; //This would be where you assign the value from your button click of row 1.
s2 = "0"; //This would be where you assign the value from your button click of row 2.
s3 = "5"; //This would be where you assign the value from your button click of row 3.
string final = s1 + s2 + s3;
int levelID = int.Parse (final);
SceneManager.LoadScene (levelID);
}
@smnerat, I seem to still have a problem. The script is okay, no errors when I debug, but when I run the game it simply opens to the new scene referenced in the script. I'm not sure what I'm doing wrong. I'm attaching the script as is to the canvas then dragging the canvas to onClick and using stringname. I don't know if this is right or not. thanks
using System; using UnityEngine; using System.Collections; using UnityEngine.Scene$$anonymous$$anagement;
public class Nextsong : $$anonymous$$onoBehaviour {
/*This is dependent on how you order your levels.
You may need to change this around a bit on your
own depending on how you want your levels loaded,
but you can assign a value from 0 to 9 for
each of the three rows, but do it as a string
and not a number.So ins$$anonymous$$d of 1 or 4,
it would be "1" or "4". Then you can
just add the strings together and convert it to an int.
For this example, I just put everything in Start(),
but you would probably want to assign each variable
on a button click and check in Update() if they are
null or not. Once all three are assigned you can go
ahead and create your levelID and load the next scene.*/
private string s1;
private string s2;
private string s3;
void Update ()
{
s1 = "0" = true; //This would be where you assign the value from your button click of row 1.
s2 = "00" = true; //This would be where you assign the value from your button click of row 2.
s3 = "000" = true; //This would be where you assign the value from your button click of row 3.
string final = s1 + s2 + s3;
int levelID = int.Parse (final);
Scene$$anonymous$$anager.LoadScene ("A00Bside");
}
}
Answer by normantheartist · Jul 31, 2016 at 01:01 PM
Thank you @Smnerat, I will try this and let you know if it works for me.
Your answer
Follow this Question
Related Questions
How to shorten this code? 2 Answers
How Can i Get This bool to work? Just need someone willing to explain. 2 Answers
PLEAASEE I NEED HELP!!! How to turn Mesh Renderer of cubes on and off by pushing buttons? 1 Answer
Linking Trigger to Input (or directly into Character Control script) 0 Answers
Why doesn't this if-statement work? 1 Answer