-
-
Notifications
You must be signed in to change notification settings - Fork 306
Adding custom sound effects (v1.7)
Written by @IvythePoS
- Get an audio file of the sound you want to add, either WAV or OGG are recommended.
- in your project, go to
Assets/Resources/Sound/
, and place your sound effect either directly in that folder or inside a subfolder that suits the sound effect best. - Look for
Enums.cs
, and inside the script, look forpublic enum Sounds : byte
. - Copy and paste (or select text, then press CTRL + D to duplicate) any sound data entry, such as:
and change the filepath within the
[SoundData("world/block_powerup")] World_Block_Powerup = 69,
SoundData
attribute to point to the audio file you just added (without "Assets/Resources/Sound"). You should also change the enum's name (currentlyWorld_Block_Powerup
), as well as its value (currently69
(it's nice indeed)). If you don't change the name of the sound, it will return an error saying that it's already defined. If you don't change the value, it will be read as the one that's already defined with another sound.
If you want a sound to play in MainMenuManager.cs
or GameManager.cs
, you can use sfx.PlayOneShot(Enums.Sounds.Your_Sound.GetClip());
where you think it's appropriate. If you have using NSMB.Extensions;
at the top of your .cs
file, you can omit the .GetClip()
.
If you want to place it in PlayerController.cs
for the player, there's three different options:
-
PlaySound(Enums.Sounds.Your_Sound);
will play it for the local player only, taking into account the camera's distance to the sound source. -
PlaySoundEverywhere(Enums.Sounds.Your_Sound);
will play it for the local player only, regardless of the camera's distance from the sound source. -
photonView.RPC(nameof(PlaySound), RpcTarget.All, Enums.Sounds.Your_Sound);
will play it for all players over the network, in the scene at your current location.Note that if you use the
photonView.RPC
version in code that runs for every player (such asPlayerController.HandleMovement
), it will play too many times. If you are unsure, add aphotonView.IsMine
check before the RPC. For example:if (photonView.IsMine) { photonView.RPC(nameof(PlaySound), RpcTarget.All, Enums.Sounds.World_Block_Bump); }