- Home /
how is it possible to make a sound based spawning system?
I am at the early stages of making a zombie game and I've been trying to make a zombie spawner that activates upon certain sounds (e.g. running sound, shooting shouts, etc) but i have no idea how to make this (im still new to coding) I AM NOT ASKING FOR THE SCRIPT TO BE MADE FOR ME... I WANT TO MAKE MY OWN but i have now idea how to right and what is used to make things in unity activate when certain sounds are made... how would i go about writing this and what is used in the script to make things triggered by sounds?
Uhm, well, if you start on your game and get more aquainted with Unity and your scripting language of choice, I am sure you will eventually figure out a solution of your own.
If I was trying something like this, my first attempt would be to call events
when certain sound clips are played by the player (like you say, shooting, running, etc), and then have my spawner object listen for these events and then do whatever logic to decide whether to spawn enemies or not, and where.
i have been making the game for a while but I've only just started with this... before the spawner is just the ordinary spawning 1 zombie per X seconds but now i want to change it to make it more like this... I've done some scripting but nothing like this before... i like you're idea... but what would i write to have the spawner listen to these sounds?
Take a look at documentation for events. Basically you define an event in the sound script, += a method to it in the spawner script, and call the event when the event should be triggered. It will call all methods added to it.
http://msdn.microsoft.com/en-us/library/edzehd2t(v=vs.110).aspx
Take a look at how the event system works in C# (if you are using JS, I can't help with that, sorry, but pretty sure you can find that information on your own).
http://unity3d.com/learn/tutorials/modules/intermediate/scripting/events
http://answers.unity3d.com/questions/593012/how-to-pass-on-information-through-c-events.html
Once you figure out how to use events, it will become evident where to go from there :)
thank u guys i'll give this a shot and see what i can get from it :D
Answer by Kumo-Kairo · Dec 13, 2013 at 06:15 PM
The point is - your sounds will be triggered by your scripts. So instead of triggering something BY sound you will trigger something SIMULTANEOUSLY WITH triggering your sound. It will be easier to implement and much easier to understand. There's no point of making these simple things so complicated
Scenario: Your player starts walking. You know that if he walks he produces step sounds. So you trigger these sound and in the exact same time, you trigger something related with this event. Same thing with shouting - you trigger shout sound AND something else on the moment you press your "SHOUT" button.
Your answer
![](https://koobas.hobune.stream/wayback/20220613124112im_/https://answers.unity.com/themes/thub/images/avi.jpg)