Game Audio Coding using FMOD

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] once you've installed the fod package you can add sounds to game object via the F1 Studio event emitter so here we get an drop down menu for how we want to trigger the sounds and then we have an event reference here so we can get the events uh which is great but this also means that the sound is attached to the game object and although we can combine them via array sometimes you want to have a controller script with the codes to trigger the MSR so let's create a logic which triggers the sound from the object and then a controller script where we can assign the event and we can change events when we want to so let's start by looking at how we play a sound from an object so I'm going to create a script here and I'm going to call it play sound and for this one I'm going to use an ont trigger event so I'm going to get rid of the initial methods here on trigger enter we'll trigger if a collider other which is the local variable and then we'll use that variable compare the tag and then if that is the player then sound will play so to make the sound play we need to call F mode so we can do F mode unity and then runtime manager and then play one shot and then we would need the path to this event so I'm going to get a call on here and I'm going to jump back to F mod I'm going to copy the path copy path go back to our script and then paste that in here let's save that and then in unity we're going to make sure that our cube is set as a trigger because we want to do the ont trigger event let's play and then we have the sound but we can simplify the script and make it a bit more accessible by taking the name space here and adding this library in the beginning of our script so using F unity and now you see they're gray out so I don't need F mod Unity anytime that I'm going to be using the runtime manager so for instance let's say that in this case I wanted to use the runtime manager and I want wanted to get a bus Which is the mixer and now instead of having to add F mode unity in front of this all the time I can just do runtime manager we can also get access to the different events by using an event reference so in the beginning of the script here I'm going to add variable which is going to be an event reference so event reference like this and I'm just going to call this event reference and I'm going to set this as public so we can get access to it outside of this script and in the inspector and then I'm going to take event reference here which are variable and I'm going to go and take away the string here which is the path and I'm going to add event reference like this so if we now grab our event sound here from the list and then we can see that we have access to all of the Sounds in our F mode session get event sound press play and then run into the cube by definition a one shot sound will trigger and then it will play the duration of the sound but if we instead have a loop we want to be able to play and then stop so to do this I'm going to add an event instance but to do this we need an additional Library so I'm going to go to using which is the namespace and the library and I'm going to go f mod and then fod studio and now I can go event instance and let's call that l event that and then we need to make some changes in our if statement here so let's get rid of this and then go Loop event Loop event equals runtime manager dot create instance that's the instance of the event that we want to create and then we need a path for this and this case we can use our event reference we can still use that as a path and then we can go Loop event and as this is now an event we can simply go start and this start method is now taken advantage of this Library here so let's save this and then we're going to change our event sound here and we're going to get the event Loop instead and press play and now this will play until we stop it so I'm going to go back into our code and I'm going to copy copy this whole thing let's tidy this up a little bit going to copy our on trigger enter and paste it and change our enter to exit we've already created our event so we just need to stop it let's get rid of the start add stop instead and if we add the parentheses here we're going to get some options here and let's do just stop mode immediate go back to Unity press let's play so as long as we're inside a cube then the sound will play and when we exit the cube exit the trigger it'll stop but we might have lots of different game objects so instead of adding each sound to each individual game object we can control them from a controller script or a manager script scpt in this case I added a game object here and I'm going to add script new script let's call this F mode controller so now what we want to happen is that when the player enters the object we want that to trigger the event uh and then when it exits we want it stop it so I'm going to get rid of these methods here and so other scripts can get hold of our stop and start method here we're going to make them Public public void start event and then we can do a public void s event and then we can simply copy the F mod coding from the play sound script and then then in our play sound uh EV we can get a hold of a reference to that script let's go public and then F mode controller and F mode controller and in our on trigger we'll do F mod controller do start event and in our stop of course we'll just take the same thing we just change that to stop so stop and we go back to Unity and then in our cubes here we need to add our scripts so I'm going to select all of them and I'm going to go to F mode controller and add that because I selected all of them then we see that they all have the script and press play and maybe the most obvious benefit of this is that I can now go to my f mode controller and I can change the sound and now all these cubes will play the new sound without me having to change it individually for each game [Music] object [Music] if we want the sound to be in 3D we need to add a 3D specializer in F mode so I'll go to the event add effect add specializer save and build that and then we need to make some changes to the script so normally when you're adding a 3D specialization in the script you will do so Loop event here do set 3D attributes and then run Time utils 3d2 3D attributes and if the script was attached to the game object that we wanted to be spatialized we would add game object to reference that however we want the position of the cube to be referenced in our F controller script so one way we can do this is to take this l local variable other and we can take the game object property of that so other do game object and then will get an error here because the receiving method doesn't have the same information so we can then add the information that we're getting from the sending script here and in this case that's game object and let's call this POS for position then instead of adding game object here which would reference the game object which this script is attached to we're now taking the position from the game object that we're calling the script from and we're calling this position here now we don't have any errors anywhere and you can see I've commented out the stop event here so we can walk away from our game object and actually hear the 3D [Music] specialization [Music]
Info
Channel: Night On Mars
Views: 131
Rating: undefined out of 5
Keywords:
Id: anX1afTL3V4
Channel Id: undefined
Length: 10min 35sec (635 seconds)
Published: Thu Dec 28 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.