SHOW:
|
|
- or go back to the newest paste.
| 1 | using UnityEngine; | |
| 2 | using System.Collections; | |
| 3 | ||
| 4 | public class EnemySound : MonoBehaviour | |
| 5 | {
| |
| 6 | AudioSource audio; | |
| 7 | ||
| 8 | - | float timer = 0f; |
| 8 | + | //float timer = 0f; |
| 9 | void Start () | |
| 10 | {
| |
| 11 | audio = GetComponent<AudioSource>(); | |
| 12 | StartCoroutine(PlayPeriodicSound()); | |
| 13 | - | audio = GetComponent<AudioSource> (); |
| 13 | + | |
| 14 | ||
| 15 | - | |
| 15 | + | |
| 16 | {
| |
| 17 | } | |
| 18 | ||
| 19 | - | timer += Time.deltaTime; |
| 19 | + | IEnumerator PlayPeriodicSound() |
| 20 | - | if (timer >= Random.Range(0.5f, 1f) && MoveDown.enemies.Length >= 20) |
| 20 | + | {
|
| 21 | - | {
|
| 21 | + | float timer = 0; |
| 22 | - | audio.Play(); |
| 22 | + | while (true) |
| 23 | - | timer = 0; |
| 23 | + | {
|
| 24 | - | } |
| 24 | + | |
| 25 | - | else if(timer >Random.Range(.3f,.7f) && MoveDown.enemies.Length <= 20) |
| 25 | + | if (MoveDown.enemies.Length > 20) //(over 20 bad guys) |
| 26 | {
| |
| 27 | - | audio.Play(); |
| 27 | + | timer = Random.Range(0.5f, 1f); |
| 28 | - | timer = 0; |
| 28 | + | } |
| 29 | - | } |
| 29 | + | else if (MoveDown.enemies.Length > 5) // (5 - 19 bad guys) |
| 30 | {
| |
| 31 | - | else if(timer >Random.Range(.1f,.3f) && MoveDown.enemies.Length <= 5) |
| 31 | + | timer = Random.Range(0.3f, .7f); |
| 32 | - | {
|
| 32 | + | } |
| 33 | - | audio.Play(); |
| 33 | + | else if (MoveDown.enemies.Length > 1) // (2-5 bad guys) |
| 34 | - | timer = 0; |
| 34 | + | {
|
| 35 | - | } |
| 35 | + | timer = Random.Range(0.1f, .3f); |
| 36 | - | else if(timer > 0.1f && MoveDown.enemies.Length <= 1) |
| 36 | + | } |
| 37 | - | {
|
| 37 | + | if (MoveDown.enmies.Length <= 1) |
| 38 | - | audio.Play(); |
| 38 | + | {
|
| 39 | - | timer = 0; |
| 39 | + | timer = 0.1f; |
| 40 | - | } |
| 40 | + | } |
| 41 | yield return new WaitForSeconds(timer); | |
| 42 | audio.Play(); | |
| 43 | } | |
| 44 | } | |
| 45 | ||
| 46 | } |