Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class EnemySound : MonoBehaviour
- {
- AudioSource audio;
- //float timer = 0f;
- void Start ()
- {
- audio = GetComponent<AudioSource>();
- StartCoroutine(PlayPeriodicSound());
- }
- void Update ()
- {
- }
- IEnumerator PlayPeriodicSound()
- {
- float timer = 0;
- while (true)
- {
- if (MoveDown.enemies.Length > 20) //(over 20 bad guys)
- {
- timer = Random.Range(0.5f, 1f);
- }
- else if (MoveDown.enemies.Length > 5) // (5 - 19 bad guys)
- {
- timer = Random.Range(0.3f, .7f);
- }
- else if (MoveDown.enemies.Length > 1) // (2-5 bad guys)
- {
- timer = Random.Range(0.1f, .3f);
- }
- if (MoveDown.enmies.Length <= 1)
- {
- timer = 0.1f;
- }
- yield return new WaitForSeconds(timer);
- audio.Play();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment