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 snowshotbullet · Aug 11, 2017 at 04:05 AM · scene-switchingscene loadscene changeif else

How to change scenes based on an if else statement C#

I'm making a rhythm game using a list, and when the tracker hits the location of, say, 3 it spawns a note on the third string. I would like to make it so that when noteMark == 72, the scene changes to (2). Unfortunately, I'm a beginner so I don't know how to make this work (have tried many times with if else statements, and javascript but i couldnt link it to the c# variable). Could somebody help me out? I'll put in the code for reference. When you answer, please also advise me WHERE to put it in the code.

 public class gm : MonoBehaviour
 {
     List<float> whichNote = new List  <float>() { 1, 6, 3, 4, 2, 5, 2, 1, 2, 3, 5, 6, 4, 6, 5, 5, 1, 2, 4, 1, 1, 4, 5, 1, 3, 2, 5, 1, 6, 4, 5, 3, 1, 2, 2, 5, 6, 2, 4, 5, 4, 1, 6, 2, 4, 3, 5, 1, 5, 4, 3, 6, 3, 2, 4, 5, 6, 4, 1, 1, 6, 2, 3, 6, 1, 6, 2, 5, 4, 1, 3, 2, 2,};
     //creates a list of values which can be called based on their position
 
     public int noteMark = 0;
     //tracks position of note, starting at 0
 
     public Transform noteObj;
     //variable storing the prefab of the note
 
     public string timerReset = "y";
 
     public float xPos;
     //the X position of where the note will be spawned (decides which of 5 rows it'll go down)
 
     public static int winStreak = 0;
     //variable for how many consecutive notes you get right
 
     public static float totalScore = 0;
     //variable for score
 
     public Transform fountainfw;
     //variable storing the prefab of the fireworks
     public string fountainSpawnL = "n";
     //variable checking whether the left fountain has been spawned
     public string fountainSpawnR = "n";
     //variable checking whether the right fountain has been spawned
 
     // Use this for initialization
     void Start()
     {
 
     }
 
     // Update is called once per frame
     void Update()
     {
         if ((timerReset == "y") && (noteMark<72))
         {
             StartCoroutine(spawnNote());
             //runs the IEnumerator code
             timerReset = "n";
             //so the notes don't spawn on top of each other every frame, timer is reset to give it enough time
         }
 
         if ((winStreak == 5) && (fountainSpawnL == "n"))
         {
             fountainSpawnL = "y";
             Instantiate(fountainfw, new Vector3(2.35f, 1.32f, 0.59f), fountainfw.rotation);
             //when winstreak is 5, first sparkle fountains comes up
         }
         if ((winStreak == 10) && (fountainSpawnR == "n"))
         {
             fountainSpawnR = "y";
             Instantiate(fountainfw, new Vector3(-2.33f, 1.32f, 0.59f), fountainfw.rotation);
             //when winstreak is 5, second sparkle fountain comes up
 
         }
     }
     IEnumerator spawnNote()
     {
         yield return new WaitForSeconds (0.7f);
         //it waits 0.65 seconds, then spawns the note
 
         if (whichNote [noteMark] == 1) {
             xPos = -1.35f;
         }
         //When the note reads value 1 on the list it spawns a note on the last string
         if (whichNote [noteMark] == 2) {
             xPos = -0.8f;
         }
         //When the note reads value 2 on the list it spawns a note on the second last string (and so on)
         if (whichNote [noteMark] == 3) {
             xPos = -0.3f;
         }
         if (whichNote [noteMark] == 4) {
             xPos = 0.35f;
         }
         if (whichNote [noteMark] == 5) {
             xPos = 0.9f;
         }
         if (whichNote [noteMark] == 6) {
             xPos = 1.3f;
         }
         noteMark += 1;
         //Moves the position of the next note
         timerReset = "y";
         Instantiate (noteObj, new Vector3 (xPos, 2.15f, -3), noteObj.rotation);
         //adds these when the program starts; the note object, the top of guitar, an the rotation of the note object
 
     }
 }
 
 
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by CurtMC · Oct 23, 2017 at 08:29 AM

 if (noteMark == 72)
 {
       SceneManager.LoadScene(2);
 }

Just add this someplace you want.

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

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

Start function not called after reloading scene 0 Answers

How I can Open a Previous Scene with button back !? 3 Answers

Trouble set the scene active with SceneMananger 1 Answer

Loading and Unloading scenes 2 Answers

Unable to get name of current scene 0 Answers


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