- Home /
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. :)
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
Your answer
Follow this Question
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