void checkSources() { heartRate = HeartRate.None; //Logic here //Loop through each thingy we are scared of, and take the one that scares us the most, and set our heart rate. //If there is nothing in the scene to scare us, then set the heart rate to be off. //But, if there is something in the scene that does scare us, anything at all, then heartrate should be slow. foreach ( FearSource source in fearSources) { if (!source.t.gameObject.activeInHierarchy) { continue; } HeartRate tempHeartRate = HeartRate.None; Vector3 offset = source.t.position - player.transform.position; float sqrLen = offset.sqrMagnitude; if (sqrLen < source.near * source.near) { //Debug.Log ("Making Heart Rate Go"); tempHeartRate = HeartBeat_ControlScript.HeartRate.Fast; } else if (sqrLen < source.medium * source.medium) { //Debug.Log ("Making Heart Rate Go"); tempHeartRate = HeartBeat_ControlScript.HeartRate.Mid; } else { tempHeartRate = HeartRate.Slow; } int result = (int)(Mathf.Max ((float)tempHeartRate, (float)heartRate)); heartRate = (HeartRate)result; } }
// Update is called once per frame void Update() { checkSources (); if (heartRate != currentlyPlaying) { switch(heartRate) { case HeartRate.None: source.Stop(); break; case HeartRate.Slow: loadAudio(slowBeat); break; case HeartRate.Mid: loadAudio(midBeat); break; case HeartRate.Fast: loadAudio(fastBeat); break; } currentlyPlaying = heartRate; } }