|
when i shoot my gun in the play bar it makes the gun shot noise when i shoot but after the seventh shot it no longer plays the audio can some one tell me what is wrong thank you! thanks but that did not work but here is the script im using:
(comments are locked)
|
|
I wasn't able to reproduce your issue. Your method "works" but setting them looping cause sound glitches. Here's a rewrite of the same code. I tested it with two different sounds and it works good for me. All I did was slap this and an AudioSource on a game object, together with two clips for the script. Instead of waiting for a timer I am checking until the sound stops. I don't use looping sounds (since this will do the loop by itself). Also I call audio.Stop() between each clip as you can see below, but I doubt it would do any difference unless you were waiting and using a looping sound (as you were originally). I am still curious about how you control the audio for the gun.
Mar 20 '11 at 07:15 PM
Statement ♦♦
error CS8025: Parsing error that is the error its giving me wtf
Mar 20 '11 at 09:06 PM
andrew 3
It's because you put JavaScript code in a C# file! You must create a JavaScript file and put the code there. If you are unsure about how, just right click in the project files list and select Create/JavaScript. Then paste the code in that file instead. If you still get the error you probably forgot to get rid of the old C# file you created.
Mar 20 '11 at 10:22 PM
Statement ♦♦
Basically there are three different languages that Unity3D supports. It's important you put the right code in the right files. C# code go in .cs files. JavaScript (also called UnityScript) goes in .js files. Boo (Python, or similar to python, I never used it) code go into .boo files.
Mar 20 '11 at 10:25 PM
Statement ♦♦
very interesting when i had while(true) it looped like it was suppose to but i had know control of the gun making the noise when i wanted to but when i put in while(false) i had control when i wanted it to make the gun shot noise but after for shots it stopped even though its a mag of 6 bullets
Mar 20 '11 at 11:46 PM
andrew 3
(comments are locked)
|
|
where here is the code im using now this one my uncle gave me (he is a programer for a living) and it still stops at four shots we know its not the script and it is not a audio listener problem because i only audio lister in the level while (vvv < 0) is going to cause you trouble since it never executes the block.
Mar 24 '11 at 11:39 AM
Statement ♦♦
This is the most difficult to answer question I've seen on Unity answers. 100 points isn't much for this one. ;)
Mar 25 '11 at 12:18 AM
Goody!
(comments are locked)
|
|
The conditional statement must be True for the while loop's code to be executed, but in your script there is:
Edit: Maybe you should use this script and assign the clip when the player presses a button: thanks but that did not work but here is the script im using // Plays back one of the audio choosing randomly between them. var clips : AudioClip[] = new AudioClip[1]; function Start () { DontDestroyOnLoad(this); audio.loop = true; while (true) { audio.clip = clips[Random.Range(0, clips.length)]; audio.Play(); if (audio.clip) yield WaitForSeconds(audio.clip.length); else yield; } } @script RequireComponent(AudioSource)
Mar 19 '11 at 03:36 PM
andrew 3
it just gave me a error Assets/NewBehaviourScript.js(7,18): BCE0043: Unexpected token: ..
Mar 20 '11 at 03:00 PM
andrew 3
you should edit line 7 and replace the 3 dots with your random function to assign the actual audio clip.
Mar 20 '11 at 04:22 PM
efge
(comments are locked)
|

maybe if you are using Input.GetKeyDown you will note this that it only going to do one time, if this is your case I recommend you to change it to Input.GetKey. If not, please specify, put your script or a description of what you have do.
here is the script i have been using // Plays back one of the audio choosing randomly between them. var clips : AudioClip[] = new AudioClip[1];
function Start () { DontDestroyOnLoad(this); audio.loop = true; while (false) { audio.clip = clips[Random.Range(0, clips.length)]; audio.Play(); if (audio.clip) yield WaitForSeconds(audio.clip.length); else yield; } }
@script RequireComponent(AudioSource)
can you please edit your post to include your script it's just a mess in a comments box
ok here i add it to the top