private void OnTriggerEnter(Collider collision) { Glove enemyGlove; //Check if the incoming collider is a glove, and is not owned by this unit. if ((enemyGlove = collision.gameObject.GetComponent <Glove>()) && collision.gameObject.GetComponent <Glove>().Self != unitHealth && enemyGlove.CombatEnabled) { // Don't judge a hit if the unit is immune. if (unitHealth.Immune || unitHealth.ImmunePenalty) { return; } // Return as a bad hit if the velocity was not sufficient. else if (enemyGlove.Velocity <= properties.hitThreshold) { FailedHit(enemyGlove.Velocity, collision, enemyGlove); return; } else { // Checks if User has punched if (unitHealth.Exhaustion < 3) { ScoreManager.HitRating rating = scoreManager.GetHitRating(); switch (rating) { case ScoreManager.HitRating.Miss: beatsImmune++; FailedHit(enemyGlove.Velocity, collision, enemyGlove); break; default: unitHealth.Exhaustion++; SuccessfulHit(enemyGlove.Velocity, collision, enemyGlove); break; } } else { // If the user has punched too many times the Enemy becomes Immune as a punish beatsImmune += 3; unitHealth.Exhaustion = 0; } } } }
/// <summary> /// Instantiates a GameObject that tells the player how good or bad their hit was. /// </summary> private void GenerateTimingFeedback() { GameObject timingText = Instantiate(Resources.Load <GameObject>("Generic/TimingText"), transform.position + textSpawnOffset, transform.rotation); TextMeshPro textMesh = timingText.GetComponent <TextMeshPro>(); ScoreManager.HitRating rating = scoreManager.GetHitRating(); switch (rating) { case ScoreManager.HitRating.Miss: textMesh.SetText("Too " + rating.ToString() + "!"); break; default: textMesh.SetText(rating.ToString() + "!"); break; } textMesh.color = ScoreManager.ratingColors[rating]; }