In this lecture I want to continue on with sounds by adding a enemy sounds and then our music.
Now let's go look at our arrow.
When an arrow gets destroyed you'd like to make a sound.
So just under objects an arrow in the step event at the point where they are always dying.
So I want to play the RR Di sand but only if the arrow is on screen it only hit or die if it happens.
A few screens away and runs into a wall.
It's just doesn't feel right to the game for us to hear that.
So we can check if the arrows on the screen by saying if on screen you remember we have a script that
checks if something is on screen and we have a buff of you that lets us then add a few more pixels to
the screen.
So then Colback on screen.
So if on screen is 40 then we can use the same method we did before by saying the image index is equal
to 1.
Then we can apply the order.
We don't want to do it at any other time because we only want to play once.
So now we can play the sandhi it's going to be aero Di and only the pro already at 20 when there is
fire under our sport.
Let's add one to that as well.
We're going to put down
and we just want the sound of our firing.
And I just it a party of 10.
Now what about when the enemies attack the player.
So let's look at the enemy attack script which is process enemy attack.
And if we look down here we're green Cheick happens and we're going to put on the bat and sand here
and we just want to play the sound of the player being hit play a hit.
And I'll give it a property of 40 because it's quite important to see when you're being hit.
Now just like the player attack there's also a chance the blocking occurs.
So down heah latera sound.
And this is where the blocking happens so we just put the blocks down here and we're going to give that
a party of 40 as well.
Now where the enemies die which happens under enemy hate you pay so you can just place that he when
play the death sound I'll say what I play sound.
We have one cold enemy dying and we give that a party of 10.
But as well as that remember these gems dropped out of the enemy's.
So let's play a jam spoon sound.
But I want to play it once so I'm not going to put it down here amongst this section.
We'll just play it here once.
And give your 15 says those are a spawn of help here.
So let's give a sample of that as well.
And HP scoring.
And we'll just add that as 15 as well.
So let's have a look at our frog and the frog jump start state where the frog actually does jump.
Let's play a sound for the frog jumping.
So just when he is where that happens and the same as with the arrow I don't want to hear the frog jumping.
If he's not on the screen so if on screen and we use the same buffer as 40 will then we can play the
sound
and just called frog jump and just put a party 20.
Now let's have a look where the frog actually does the attack.
So once again we only want to play it on that first frame so he can come in here and say it's image
index is equal to five.
Then we want to play the sound of a frog attacking and I'll give it a property of 15.
Now what about a chest or chest opens up and the gems pop out.
So that happens in here.
So after gems are created the have a say on here I'm going to do something here to change the sound
of the jams.
I'm going to vary the pitch when they spawned.
And by that I mean if I have the same sound when they all come and this will sound a little odd so I'm
going to set a variable called S&P and I'm going to set a sound to that variable
and I'll have 15.
And by setting that like that I can then use audio on the school sound on the pitch and I can change
the pitch of a sound.
And in this case it's going to be Sandy and the pitches only set to one so we can change it by using
a random range and just have a go between 0.9 and 1.1 and that'll just vary it slightly.
Now when the play starts the game.
So we got to our game we got gradual gooey and we go to where the player actually clicks start.
Just in here.
So we can have a sound that makes the game start at that point and we get the game start now to set
to 15.
Let's go to the bug and at the point where he actually spots the player.
So in the Idol where he actually sees the player for the first time let's make a sound.
So the player knows that he's been spotted.
So right here we just have one called Bug C's player and all set to 40 codes important to play and knows
that that's happened.
I'm going to take a copy of that because we also want that in the petrol state at the point he where
he sees the player.
So once you're in the chase state I want him to make a sound while chasing the player.
So when he we can just add a and doesn't really matter way down here.
But once again we don't want this to play every single step otherwise we're going to have to sound overlapping.
We need to check that it's not playing.
So it's not audio is playing and the sound is called Sound bug chase we'll then we can play it
and slow the property a little bit for that.
Now the last thing I want to do is add the music so we can do that by going to a game and going to a
room stopped.
So let's head down here how to play the music.
Now we just need to drag the music in.
So just on the music take these two drag the mean
those two different tunes is one for when you normally playing in one for the end line.
So if our room is equal to room game and then we want to stop the game music and we want to play the
end game music.
Or else we just want to play the game music because we do that when we can stop it by saying audio stop
sound and the sound is called Sound on disco music.
Middle Park.
And then we want to play the music.
So sound music gaming and so just keep that approach to attain.
Now down here if the room is not the room game and will that's any other time during the game we just
want to play the normal music but we don't want to play it.
If it's already being played.
So we need to say if not audio is playing of sound and music.
Middle Park will be in.
We can play it.
So I'm going to give that a party of 20.
Now the other thing I want to change is the false.
I want to change to a true which means the music will loop after it finishes.
So let's test it out.
Starting sound.
And what a difference it makes to the game just to hear those sounds to me.
Yeah that's right.
Just hear this Sam
and hear the different pitch in those jams just gives us some variety when it's opening and arises as
well that's all looking really good.
So that's all for this lecture.
Thanks for joining me.
I'll talk to you in the next.