Hi,
I have this script attached to my gun :
var rifle : AudioClip;
function Update() {
if (Input.GetButton("Fire1")) {
animation.Play("AnimationEnfield");
audio.PlayOneShot(rifle);
}
}
It works, but what happens is the rifle sound plays continuously when you click fire. I need to be able to stop the audio playing until the animation is finished, so really I need to play the audio and wait three seconds before I can do it again. Could someone help me please?
qJake
2
Use `Input.GetButtonDown()`, not `GetButton()`.
You can check if an animation is playing or not using the isPlaying property.
http://unity3d.com/support/documentation/ScriptReference/Animation-isPlaying.html
Adding to what SpikeX said, to set a reload time, you can do something like:
var reloadTime : float = 3.0;
private var fireTime : float;
function Update() {
if (Input.GetButtonDown("Fire1") && Time.time - reloadTime >= fireTime) {
animation.Play("AnimationEnfield");
audio.PlayOneShot(rifle);
fireTime = Time.time;
}
}