-
-
Save DeKoServidoni/c43fe0e6296362e8ca840aee0eb52739 to your computer and use it in GitHub Desktop.
Player Sound Effects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
public class PlayerSFX : MonoBehaviour { | |
[SerializeField] AudioSource _audioSource; | |
[Header("Sounds")] | |
[SerializeField] SoundSO _jumpSFX = null; | |
[SerializeField] SoundSO _attackSFX = null; | |
[SerializeField] SoundSO _hitSFX = null; | |
public void PlayJumpSound() { | |
PlayOneShot(_jumpSFX.clip, _jumpSFX.volume); | |
} | |
public void PlayAttackSound() { | |
PlayOneShot(_attackSFX.clip, _attackSFX.volume); | |
} | |
public void PlayHitSound() { | |
PlayOneShot(_hitSFX.clip, _hitSFX.volume); | |
} | |
private void PlayOneShot(AudioClip clip, float volume) { | |
if (_audioSource == null) | |
return; | |
_audioSource.PlayOneShot(clip, volume); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
[CreateAssetMenu(menuName = "Sounds/SFX")] | |
public class SoundSO: ScriptableObject { | |
[SerializeField] string _name; | |
[SerializeField] AudioClip _clip; | |
[SerializeField][Range(0f, 1f)] float _volume = 0.0f; | |
[SerializeField][Range(.1f, 3f)] float _pitch = 0.1f; | |
[SerializeField] bool _loop = false; | |
public new string name { get { return _name; } } | |
public AudioClip clip { get { return _clip; } } | |
public float volume { get { return _volume; } } | |
public float pitch { get { return _pitch; } } | |
public bool loop { get { return _loop; } } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment