- Home /
How to add jumpscare sound effects when you looks enemy?
Hi! I am beginnig in unity, and I am making an horror game. I would like to add a jumpscare sound effect when the player is looking the enemy, like in movies, or games like scp 087-b or others. ( Sorry for my English) So, please can you tell me the script who can do that?
Happy hollydays.
Answer by Ben Ezard · Dec 27, 2012 at 02:04 PM
You can use: var enemy : GameObject; //the enemy
var soundEffect : AudioClip; //the sound effect that you want to be played when you see the enemy
function Update() {
if (enemy.renderer.isVisible && !audio.isPlaying) { //if the camera can see the enemy, and the sound effect isn't already playing
audio.clip = soundEffect; //assign the sound to the audio's clip
audio.Play(); //play the sound
}
}
O$$anonymous$$ i am going to try, but please, can you tell me how to modify this sound?( I am null in scripts )
In the inspector view (the view where you can see stuff in your scene), click on the object that you've attached the script to You should see something like "Sound Effect: Audioclip (none)" under the name of the script - click on this, and then select the the sound effects that you want from the list that appears (you have to put it in the Assets folder first remember) Hope this helps, if you're still stuck t+en I can do a picture tutorial or something :)
Here's a picture of what to do: http://ezardlabs.co.uk/images/Capture.PNG Also, replace your current script with the one above - I fixed something on it You'll also need to add an AudioSource component to the gameobject that has the jumpscare script attached
"$$anonymous$$issingComponentException: There is no 'AudioSource' attached to the "$$anonymous$$ain Camera" game object, but a script is trying to access it. You probably need to add a AudioSource to the game object "$$anonymous$$ain Camera". Or your script needs to check if the component is attached before using it. JumpscareScript.Update () (at Assets/JumpscareScript.js:4)"
I don't really understand...
Your answer
Follow this Question
Related Questions
Shooting script problem. 2 Answers
Creating a walking animation. Need help! 1 Answer
How to make a house? 0 Answers
How to make a image flash infront of the camera 1 Answer
FPS Controller problems 4 Answers