private void CalculateRating() { //Debug.Log("CalculateRating"); //efficiency = (((enemiesKilled - playerDeaths) / totalNumberOfEnemies) * 100); efficiency = enemiesKilled - playerDeaths; efficiency /= totalNumberOfEnemies; efficiency *= 100; //Debug.Log("efficiency:" + efficiency); if (efficiency >= 85) { scoreRating = ScoreRating.S; } else if (efficiency >= 75) { scoreRating = ScoreRating.A; } else if (efficiency >= 65) { scoreRating = ScoreRating.B; } else if (efficiency >= 55) { scoreRating = ScoreRating.C; } else if (efficiency < 55) { scoreRating = ScoreRating.D; } gradeText.text = scoreRating.ToString(); }
// Notify this object of a Bar thats happening. public void BarSubscriber(ScoreRating rating = ScoreRating.UNRATED) { currentRating = rating; FramesSinceMayorBeat = 0; if (!isMuted) { audioSource.PlayOneShot(conga_bar); } }
// Update is called once per frame // TODO sync with music (use the beat and bar subscriber properly) // TODO consider using fixed rate update for scaling changes instead of frame based? void Update() { if (!isPaused) { if (FramesSinceMinorBeat < 5) { PulsingObject.transform.localScale += new Vector3(0.01f, 0.01f, 0.01f); SetMaterialColor(); } else if (FramesSinceMinorBeat < 10) { PulsingObject.transform.localScale -= new Vector3(0.01f, 0.01f, 0.01f); currentRating = ScoreRating.UNRATED; SetMaterialColor(); } if (FramesSinceMayorBeat < 5) { PulsingObject.transform.localScale += new Vector3(0.02f, 0.02f, 0.02f); SetMaterialColor(); } else if (FramesSinceMayorBeat < 10) { PulsingObject.transform.localScale -= new Vector3(0.02f, 0.02f, 0.02f); currentRating = ScoreRating.UNRATED; SetMaterialColor(); } FramesSinceMayorBeat += 3; FramesSinceMinorBeat += 3; // TODO remove this from here and call Beat and BarSubscriber from the correct place if (FramesSinceMinorBeat == 30) { BeatSubscriber(ScoreRating.OK); } if (FramesSinceMayorBeat == 120) { BarSubscriber(ScoreRating.PERFECT); } } }
// Notfiy this object of a Beat thats happening public void BeatSubscriber(ScoreRating rating = ScoreRating.UNRATED) { currentRating = rating; FramesSinceMinorBeat = 0; beat_counter = (beat_counter + 1) % 4; if (!isMuted) { switch (beat_counter) { case 0: audioSource.PlayOneShot(clave_beat1); break; case 1: audioSource.PlayOneShot(clave_beat2); break; case 2: audioSource.PlayOneShot(clave_beat3); break; case 3: audioSource.PlayOneShot(clave_beat4); break; default: break; } } }