- Home /
hey here wesley again sound for my gun
hey can somebody help me out please? here is the problem i want to fire my gun (that works)But i want also at the same moment to play the gun firesound this is my script
What did i do wrong?
function Update() { if( Input.GetButtonDown( "Fire1" ) ){ audio.play("p90"); } } }
and do i need to attach the script to the buller or to the p90 gun
the guns are named p90 the gun fire sound is named p90.mp3
tanks by the way greats wesley
Answer by Bunny83 · Dec 30, 2010 at 06:41 PM
First you need an AudioSource component on the gameobject. (otherwise audio is null) You can assign an AudioClip to the AudioSource in the editor.
audio.Play() doesn't take a string argument. you can specify at which sample the clip should start playing (or omit the parameter to play from start)
[...]
{
audio.Play();
You can also set a different clip by assigning an audioClip-reference to audio.clip
var P90Sound : AudioClip;
[...]
{
audio.clip = P90Sound;
audio.Play();
or Play the sound as OneShot:
var P90Sound : AudioClip;
[...]
{
audio.PlayOneShot(P90Sound);
you could also add an audio source (component>rendering>audio source)to you bullit that way when the bullit hits something and destroys itself the audio will stop
Your answer
Follow this Question
Related Questions
How to add sound to gun shot script 4 Answers
Machine gun sound — better to loop individual bullets or have a longer sample? 0 Answers
gun fire sound 2 Answers
Automatic gun sound freaking out 4 Answers
Temporarily disable audio? 1 Answer