Adding some sounds!

I wanted a beep sound for my game similar to a metal detector so I thought about what makes a beeping noise and remembered that I had recorded my microwave beeping for a previous sound project. 

I opened Audition and cut out the beep sounds. I then placed them an equal distance apart and adjusted the pitch so the sound was slightly less annoying and also the pitch got lower for when the character is far from danger. I created 3 sounds for this called Danger1 2 and 3 (1 being closest to the trap or treasure).

To add these to the game I created a new script called "PlayerCollisions" which would be for when the player collides with the tiles' colliders. When creating the prefabs for the tiles I made sure they had matching tags for the type of tile. This made it quite easy to identify the type of tile the player was on with OnTriggerEnter. To check this worked I added a Debug.Log which would say the tile type in the console. I had to make sure all the colliders were set to triggers and it worked. 

I then added the sounds by looking at my code from the previous project. I worked out that separate Audio sources would be better than assigning audio clips since I wanted the sound to loop while the character was still on the tile. 

In my first test of the script I set the sounds to stop when the character exited the collider (OnTriggerExit), however if the character went onto the same tile type this would stop and start the same sound and would sometimes cause problems, therefore I had to find a different way to stop the sounds. 

I thought about adding a delay and an if statement to check if and int called CurrentDanger (Which was updated upon entering a tile collider), however I couldn't get this to work and it didn't seem the most reliable way to do this. 

I then took a break from scripting and realised I could add to the OnCollisionEnter script and check if the sound was already playing before playing it and also stopping the other sounds. 


My next step will be getting sounds for the treasure and danger, making a few more animations and also the texture for the terrain. I also plan to add some effects. 

Comments

Popular Posts