Skip to content

Instantly share code, notes, and snippets.

@smkplus
Created April 9, 2020 16:07
Show Gist options
  • Save smkplus/5c30286d7fbb5c05bc0d717586b35464 to your computer and use it in GitHub Desktop.
Save smkplus/5c30286d7fbb5c05bc0d717586b35464 to your computer and use it in GitHub Desktop.
using UnityEngine;
public class AudioComponent : MonoBehaviour
{
//Audio Clips
[SerializeField] private AudioClip attackSfx;
[SerializeField] private AudioClip playerDeathSfx;
//Audio Sources
[SerializeField] private AudioSource audioSource;
public void PlayAttackSfx()
{
if (audioSource != null && attackSfx != null)
{
audioSource.clip = attackSfx;
audioSource.Play();
}
}
public void PlayPlayerDeathSfx()
{
if (audioSource != null && playerDeathSfx != null)
{
audioSource.clip = playerDeathSfx;
audioSource.Play();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment