/// <summary> /// Grabs the food. /// </summary> /// <param name="food">Food that Sam collided with.</param> private void grabFood(Food food) { //creates an Audio Source on Sam if there isn't one already if (!GetComponent <AudioSource>()) { gameObject.AddComponent <AudioSource>(); } //stores Sam's audio source AudioSource audioSource = GetComponent <AudioSource>(); //plays the audio on the food audioSource.clip = food.getAudio(); audioSource.Play(); //checks if food is healthy, and if so, increments counter and increases speed if (food.isHealthy()) { healthyFood++; ++healthyStreak; if (healthyStreak >= 3 && healthyStreak < 7) { ++healthyFood; } else if (healthyStreak >= 7 && healthyStreak < 12) { healthyFood += 2; } else if (healthyStreak >= 12 && healthyStreak < 20) { healthyFood += 3; } else if (healthyStreak >= 20) { healthyFood += 4; } controller.updateScrollSpeed(1); healthyText.text = healthyFood.ToString(); healthyText.transform.localScale = scoreSize * 4.5f; } //checks if food is unhealthy, and if so increments counter and decreases speed else { unhealthyFood++; healthyStreak = 0; controller.updateScrollSpeed(-1); unhealthyText.text = unhealthyFood.ToString(); unhealthyText.transform.localScale = scoreSize * 4.5f; } // Update streak text. if (healthyStreak >= 3 && healthyStreak < 7) { streakText.text = "HEALTHY\n2X BONUS"; streakText.color = Color.white; streakText.transform.localScale = streakSize * 1.5f; } else if (healthyStreak >= 7 && healthyStreak < 12) { streakText.text = "HEALTH MASTER\n3X BONUS"; streakText.color = Color.cyan; streakText.transform.localScale = streakSize * 1.5f; } else if (healthyStreak >= 12 && healthyStreak < 20) { streakText.text = "HEALTH DEMI-GOD\n4X BONUS"; streakText.color = new Color(19, 239, 140); streakText.transform.localScale = streakSize * 1.5f; } else if (healthyStreak >= 20) { streakText.text = "HEALTH GOD\n5X BONUS"; streakText.color = new Color(255, 173, 33); streakText.transform.localScale = streakSize * 1.5f; } controller.updateScore(healthyFood); //removes the food from existence food.remove(); }