/** * this function checks if the score earned on this level this time is the highest score EVER */ void saveHighScore() { prevHighScore = PlayerPrefs.GetInt("Mouth" + (level.getLevel() - 1)); // get the old saved high score // check if high score if (prevHighScore < numStars) { // if it is the high score save it prevHighScore = numStars; PlayerPrefs.SetInt("Mouth" + (level.getLevel() - 1), numStars); // save the score PlayerPrefs.Save(); // needs to be called to write the data to disk } }
/** * Draws the background image for the mouth loading screen */ void OnGUI() { counter = GameObject.Find("MouthChooseBackground"); // find the reference to the mouth background choser level = counter.GetComponent <MouthLoadLevelCounter> (); // get the current level from the counter // draw the proper level load screen to take up the entiere screen GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), backgrounds [Mathf.Clamp(level.getLevel() - 1, 0, level.getMaxLevels())]); }
public bool end = false; //!< flag to indicate whether we are at the end of the script /** * Use this for initialization * Verifies the level was loaded correctly and if not reloads it. * Starts loading from script/debugger. */ void Start() { level = null; // set the MouthLoadLevelCounter to null to begin with // find the reference to the mouth debugger debugConfig = GameObject.Find("Debugger").GetComponent <EsophagusDebugConfig>(); if (debugConfig == null) // if we are starting the game directly we need to add debugger { debugConfig = gameObject.AddComponent <EsophagusDebugConfig>() as EsophagusDebugConfig; } // find the background chooser GameObject chooseBackground = GameObject.Find("MouthChooseBackground"); if (chooseBackground != null) // if we did find the background chooser, get the level from it { level = chooseBackground.GetComponent <MouthLoadLevelCounter>(); } else // in this case we started the game load game properly { // this will cause the mouth game to be properly loaded from level 1 PlayerPrefs.SetInt("DesiredMouthLevel", 1); PlayerPrefs.Save(); Application.LoadLevel("LoadLevelMouth"); } // we also need to find the references to the flaps GameObject flaps = GameObject.Find("Flaps"); // find the reference to the flaps flap = flaps.GetComponent <openFlap>(); // get the openFlap script from the flaps if (level != null) // guard for if level was null since this will still execute before the reloading from level 1 { // finally load the script loadScript = new LoadScriptMouth(); // create a new script loader waves = loadScript.loadMouthLevel(level.getLevel()); // load the proper script to the level and store data // begin parsing the data currentWave = 0; // reset the current wave counter to 0 waveDelay = waves[0].startDelay; // get the waveDelay for the current wave waveTime = waves[0].runTime; // get the waveTime for the current wave SpawnInterval = waves[0].foodSpawnInterval; // get the spawnInterval for the current wave speed = waves[0].foodSpeed; // get the foodSpped for the current wave m_TimeSinceLastSpawn = 0f; // reset the time since last spawn to 0 } }