- Home /
audio problems with my trigger script, help please
i have an annoying problem with a script that i have made, my audio clip of a minigun is 2 seconds long and my script is only playing one and a half gunshot before starting the sound again. i have been playing around for hours now and i cannot figure out the problem. so i have posted my 'original unmangled' script to get help with my problem
that would be awesome, thanks
var Rocket_fireRate : float = 0.5;
var fireRate : float = 0.01;
private var nextFire : float = 0.0;
var rocket : GameObject;
var projectile : GameObject;
var MachineGun_sound: AudioClip;
function Start (){
audio.clip = MachineGun_sound;
}
function Update () {
if (Input.GetButton ("Fire1")){
audio.Play();
if (Time.time > nextFire) {
nextFire = Time.time + fireRate;
var prijectile : GameObject =
Instantiate(projectile, transform.position, transform.rotation) as GameObject;
}
}
else{;audio.Stop();}
if (Input.GetButton ("Fire2") && Time.time > nextFire) {
nextFire = Time.time + Rocket_fireRate;
var rocket : GameObject =
Instantiate(rocket, transform.position, transform.rotation) as GameObject;
}
}
Does adjusting fire rate change anything? $$anonymous$$aybe change the sound effect to a single shot, and clean up the looping of it real good, then just use the shorter loop.
Also, maybe just play another loop if there is no audio playing, by checking "isplaying" through code
Oh another thing, what's with prijectile? Shouldn't you use projectile?
Answer by tommy1235 · Feb 02, 2013 at 09:44 AM
thank you, MD_Reptile you reminded me about isPlaying and i added this
if (audio.isPlaying == false) {
audio.Play();
}
to my code, thanks
Your answer
Follow this Question
Related Questions
Life script how to add. 1 Answer
make my jump anim complete before walk anim starts? 2 Answers
infinite runner HELP 1 Answer
Can't change color of terrain during runtime... [SOLVED] 0 Answers
Audio Help! 1 Answer