/** * Update is called once per frame * Checks if a cough is happening. */ void Update() { if (flapScript.isCough()) // check if there is currently a cough happening { foodChain = 0; // if there is a cough happening, we reset the "chain length" variable to 0 } }
/** * On trigger enter is called when the object enters a collision. * In this script this function causes select statistics for the game to update, and performs * updates to the oxygen bar and flaps based on a cough happening. */ void OnTriggerEnter(UnityEngine.Collider other) { if (!flap.isCough()) { if (other.gameObject.name.Contains("MouthFoodContainer")) // check to see if the flaps collided with something // with the tag "foodstuff" { // track stats PlayerPrefs.SetInt("MouthStats_timesCoughed", PlayerPrefs.GetInt("MouthStats_timesCoughed") + 1); PlayerPrefs.Save(); oxygen.percent -= .07f; // on cough we decrease oxygen by a chunk amount as a penalty flap.setCough(); // set the cough indicate variable on the script } } }
/** * Update is called once per frame * Finds out if flap is open or not and updates oxygen percentage accordingly */ void Update() { previousPercent = percent; if (config.debugActive) // check if we are using debugger values or reading from the script { depletionRate = config.oxygenDeplete; // if necessary get the depletion rate set in the debugger gainRate = config.oxygenGain; // if necessary get the gain rate set in the debugger } if (flap.isEpiglotisOpen() || flap.isCough()) // check if the flap is open or a cough is happening { percent -= depletionRate * Time.deltaTime; // if either is the case the oxygen should decrease } else { percent += gainRate * Time.deltaTime; // otherwise the oxygen should gain } percent = Mathf.Clamp(percent, 0, 1f); // clamp the value between 0 and 1 so the bar doesn't over or under flow if (percent > 0.5 && previousPercent < 0.5) { YayPopup = true; timer = Time.time; AhahaPopup = false; } if (percent < 0.5 && previousPercent > 0.5) { AhahaPopup = true; timer = Time.time; YayPopup = false; } if (YayPopup && Time.time - timer > 2.0f) { YayPopup = false; } if (AhahaPopup && Time.time - timer > 2.0f) { AhahaPopup = false; } }
/** * Update is called once per frame * Checks for updated values from the debugger. Checks for coughs and coordinates food movement with cough actions. */ void Update() { //Debug.Log ("Food Time scale:" + Time.timeScale + ", x:" + transform.position.x + ", y:" + transform.position.y); // check if we are using the debugger for values, and if we are the food speed is taken from the debugger // rather than from the script if (debugConfig != null && debugConfig.debugActive) { foodSpeed = debugConfig.foodSpeed; } Quaternion q = transform.rotation; if (flap.isCough()) // if a cough is currently occuring { b.enabled = false; // reverse the path and set the "corrected" forward path position based on this reversed path transform.position = Spline.MoveOnPath(iTweenPath.GetPathReversed("Path"), transform.position, ref reversePosition, coughSpeed, 100, EasingType.Linear, false, false); pathPosition = 1f - reversePosition; if (reversePosition > .99f) // check if food near the mouth opening "fell out" of the mouth // if it did then we destroy this food and don't allow it to come back { // track stats PlayerPrefs.SetInt("MouthStats_foodLost", PlayerPrefs.GetInt("MouthStats_foodLost") + 1); PlayerPrefs.Save(); // needs to be called to write playerprefs data to disk Destroy(gameObject); // destroy the food that fell out } } else // if a cough is not occuring { if (!flap.isEpiglotisOpen()) { b.enabled = true; } // move the food down the normal path and set the "corrected" reverse path position based on this transform.position = Spline.MoveOnPath(iTweenPath.GetPath("Path"), transform.position, ref pathPosition, ref q, foodSpeed, 100, EasingType.Linear, false, false); reversePosition = 1f - pathPosition; } quaternion.Value = q; transform.rotation = quaternion; }
/** * Update is called once per frame * Checks for updated wave values from the debugger and handles the spawning of food based on parsed wave data */ void Update() { if (flap.isCough()) // if we are currently coughing, don't do any other updates for this script { return; } if (waveDelay < 0 && !end) // if we aren't currently waiting for a delay and the script isn't over { waveTime -= Time.deltaTime; // decrement the timer for the length of the current wave if (waveTime > 0) // if there is still more time in the current wave continue processing it { if (debugConfig.debugActive) // if we are using debugger values, get the spawn interval from the debugger { SpawnInterval = debugConfig.foodSpawnInterval; } m_TimeSinceLastSpawn += Time.deltaTime; // increase the timer counting the time since the last spawn if (m_TimeSinceLastSpawn >= SpawnInterval) // if the time since the last spawn exceeds the spawn interval // we need to spawn a new foodstuff { // create a new foodstuff instance GameObject foodInstance = (GameObject)Instantiate(food, startingSpawn, Quaternion.identity); // get the script on the foodstuff to change some values MoveFood moveFoodScript = foodInstance.GetComponent <MoveFood>(); moveFoodScript.foodSpeed = speed; // set the speed the foodstuff will move m_TimeSinceLastSpawn = 0; // reset the time since last spawn timer } } else // otherwise, if the time for the current wave is over, move to the next one { if (debugConfig.debugActive) // check if we are using values from the debugger, and if we are get the values { // get the values from the debugger waveDelay = debugConfig.waveDelay; waveTime = debugConfig.waveTime; SpawnInterval = debugConfig.foodSpawnInterval; speed = debugConfig.foodSpeed; m_TimeSinceLastSpawn = 0; // reset the timeSinceLastSpawn counter } else // otherwise we are getting the values from the script { currentWave++; // increase the counter for the current wave we are on if (currentWave == waves.Length) // check if the script is done, if it is throw the flag { end = true; } else // otherwise get the values for the next wave from the script { // get variable values from the script waveDelay = waves[currentWave].startDelay; waveTime = waves[currentWave].runTime; SpawnInterval = waves[currentWave].foodSpawnInterval; speed = waves[currentWave].foodSpeed; m_TimeSinceLastSpawn = 0; // reset the timeSinceLastSpawn counter } } } } else { waveDelay -= Time.deltaTime; // count down the wave delay timer if we have a delay between waves } }