TargetScript.cs
1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using UnityEngine;
using System.Collections;
// ----- Low Poly FPS Pack Free Version -----
public class TargetScript : MonoBehaviour {
float randomTime;
bool routineStarted = false;
//Used to check if the target has been hit
public bool isHit = false;
[Header("Customizable Options")]
//Minimum time before the target goes back up
public float minTime;
//Maximum time before the target goes back up
public float maxTime;
[Header("Audio")]
public AudioClip upSound;
public AudioClip downSound;
public AudioSource audioSource;
private void Update () {
//Generate random time based on min and max time values
randomTime = Random.Range (minTime, maxTime);
//If the target is hit
if (isHit == true)
{
if (routineStarted == false)
{
//Animate the target "down"
gameObject.GetComponent<Animation> ().Play("target_down");
//Set the downSound as current sound, and play it
audioSource.GetComponent<AudioSource>().clip = downSound;
audioSource.Play();
//Start the timer
StartCoroutine(DelayTimer());
routineStarted = true;
}
}
}
//Time before the target pops back up
private IEnumerator DelayTimer () {
//Wait for random amount of time
yield return new WaitForSeconds(randomTime);
//Animate the target "up"
gameObject.GetComponent<Animation> ().Play ("target_up");
//Set the upSound as current sound, and play it
audioSource.GetComponent<AudioSource>().clip = upSound;
audioSource.Play();
//Target is no longer hit
isHit = false;
routineStarted = false;
}
}
// ----- Low Poly FPS Pack Free Version -----