Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by normantheartist · Jul 29, 2016 at 07:29 PM · scripting problembooleanbuttonsif-statements

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!!!!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

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);
     }
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image normantheartist · Aug 02, 2016 at 08:58 PM 0
Share

@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");
 }

}

avatar image
0

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

77 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges