- Home /
Problems implementing sound for machine gun enemy:
I'm using the generic sentry gun as outlined in the FPS tutorial, and have had a frustrating problem implementing sound. The tutorial describes how to put the sound in for the machine gun weapon, but it doesn't describe such a method for the sentry, and none of the obvious approaches seem to work.
I've tried attaching sounds to every aspect of the sentry, the muzzle flash, the impact sparks, etc, but I can't get it to make any noise. I'm using the sentry for a "run for cover" sort of challenge, so sound is very important (the player needs to know when it's stopped firing).
This isn't just for fun, I need this for a "build a level in two weeks" test for a game design job. My future in the industry depends on getting this right, so any help would be appreciated!
Answer by oliver-jones · Nov 25, 2010 at 06:29 AM
Okay doky, lets see what we can do here.
In your script, I'm assuming you will have a line of code that says:
// If we are almost rotated towards target - fire one clip of ammo
var forward = transform.TransformDirection(Vector3.forward);
var targetDir = target.position - transform.position;
if (Vector3.Angle(forward, targetDir) < shootAngleDistance)
Simply add an:--> After the if statement
audio.Play();
What you want to do now is add an audio source to your turret, then drag your audio file into that source, and check play automatically OFF. Play the game and it should work, if not, Restart Unity. There is a bug in unity where the audio cuts out sometimes.
Answer by kkk · Dec 31, 2010 at 12:18 PM
Hi there i am looking for ww1 it says u will tell me about it. obviously not!
a)pick a better username, that one is offensive b)wth are you talking about? c)this is a community for people using Unity, a game developement program. Welcome. While some games may be about ww1, i would not recommend trying to learn about ww1 from any of the questions posted on here, as most, if not all, are about technical game issues, not subject matter such as ww1. if your reading is better than your spelling or grammar, i recommend you go to a library or find a website that is clearly about ww1
Your answer
![](https://koobas.hobune.stream/wayback/20220613084445im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Im trying to make a gun shoot sound 1 Answer
how to make gunshots 0 Answers
'FPS Tutorial' Machine Gun Script not working 7 Answers
Firing Sound 2 Answers