View difference between Paste ID: XJT4QjH1 and HHbCk8Ps
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;
9
	void Start () 
10
	{
11
		audio = GetComponent<AudioSource>();
12
		StartCoroutine(PlayPeriodicSound());
13
	}
14
15
	void Update () 
16
	{
17
	}
18
19
        IEnumerator PlayPeriodicSound()
20
        {
21
            float timer = 0;
22
            while (true)
23
            {
24
25
                if (MoveDown.enemies.Length > 20) //(over 20 bad guys)
26-
		        {
26+
27
                    timer = Random.Range(0.5f, 1f);
28
                }
29-
		        else if (MoveDown.enemies.Length > 5) // (5 - 19 bad guys)
29+
		else if (MoveDown.enemies.Length > 5) // (5 - 19 bad guys)
30-
		        {
30+
31
                    timer = Random.Range(0.3f, .7f);
32
                }
33-
		        else if (MoveDown.enemies.Length > 1) // (2-5 bad guys)
33+
		else if (MoveDown.enemies.Length > 1) // (2-5 bad guys)
34
                {
35
                    timer = Random.Range(0.1f, .3f);
36
                }
37
                if (MoveDown.enmies.Length <= 1)
38
                {
39
                    timer = 0.1f;
40
                }
41
                yield return new WaitForSeconds(timer);
42
                audio.Play();
43
            }
44
        }	
45
46
}