Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by jtok4j · Jan 18, 2015 at 01:34 PM · c#scenevariableif

Help with comparing what scene is loaded

Ok Awesome Answers Community:

I'm kind of pulling my hair out, with the code I've slapped together not doing what I think it should do...

I want to check the particular scene that's currently loaded, and then set a timer value according to that particular scene (and difficulty level)

here's the wonderful code in C#:

         void Awake () {
             levelName = Application.loadedLevel;
             Debug.Log (Application.loadedLevel + "Is the Level which is loaded.");
         }
 
 
     void Start () {
 
     
             if (gamedifficulty.difficultylevel == "Boring") {
                         
                 if (levelName == (1)) ;{
                     Timing = 20f; }
                 Debug.Log ("Set Game Timer to be 20 seconds");
                 Debug.Log (Application.loadedLevel + "Is the Level which is loaded.");
                 if (levelName == (2)) ;{
                     Timing = 20f; }
                 Debug.Log ("Set Game Timer to be 20 seconds");
                 Debug.Log (Application.loadedLevel + "Is the Level which is loaded.");
                 if (levelName == (3)) ;{
                     Timing = 25f; }
                 Debug.Log ("Set Game Timer to be 25 seconds");
                 Debug.Log (Application.loadedLevel + "Is the Level which is loaded.");
                 if (levelName == (4)) ;{
                     Timing = 20f; }
                 Debug.Log ("Set Game Timer to be 20 seconds");
                 Debug.Log (Application.loadedLevel + "Is the Level which is loaded.");
                 if (levelName == (5)) ;{
                     Timing = 20f; }
                 Debug.Log ("Set Game Timer to be 20 seconds");
                 Debug.Log (Application.loadedLevel + "Is the Level which is loaded.");
                 if (levelName == (6)) ;{
                     Timing = 30f; }
                 Debug.Log ("Set Game Timer to be 30 seconds");
                 Debug.Log (Application.loadedLevel + "Is the Level which is loaded.");
 
                 Debug.Log ("Set Game Time  through TimerOriginal Script");
                 Debug.Log (Application.loadedLevelName + "Is the Level which is loaded.");

 

(Writing resumes - Code finished) Note: (That levelName Variable is an int. )

So, the result is that it goes through the whole list of if statements and find each of them true, one by one, and sets the timer to 20 secs, then to 20 secs, then to 25, then to 20, and again 20, and finally to 30 seconds.

(All the while Debug.Log is reporting the same thing after each statement: 1 Is the Level which is loaded. UnityEngine.Debug:Log(Object) )

(1 is the scene #1... )

So, I'm pulling my hair out trying to figure out why this is happening? From my understanding, I've recorded the current scene in "levelName" by using ApplicationloadedLevel, and it's reporting that the number of the scene is : 1 But all the if statements seem to be reporting that the levelName is equal to the number (2,3,4 etc) that they're checking...

I'm sure there's something obvious that I'm missing here. Thanks for helping me find it. :)

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
Best Answer

Answer by jtok4j · Jan 18, 2015 at 01:39 PM

Well,

Stupid error, I guess. As soon as I posted the Code, I saw the additional line endings (; ) after the beginning of each "if" statement. (Sigh.)

Thanks and hopefully this helps someone else! :D

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

26 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

Related Questions

Multiple Cars not working 1 Answer

Where is the Mistake in my Coin System? 1 Answer

Distribute terrain in zones 3 Answers

I´ve got a problem with my Coin System. It always shows 1 Coin. 2 Answers

Death Counter Resets When Reloading Scene. 3 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