using UnityEngine; [RequireComponent(typeof(AudioSource))] public class AudioManager : MonoBehaviour { [SerializeField] private AudioSource footstepSource; [SerializeField] private AudioClip[] footsteps; [SerializeField] private AudioClip[] land; [SerializeField] private AudioClip[] slide; public void PlayFootstep() { footstepSource.PlayOneShot(footsteps[Random.Range(0, footsteps.Length - 1)]); } public void PlayLand() { footstepSource.PlayOneShot(land[Random.Range(0, land.Length - 1)]); } public void PlaySlide() { footstepSource.PlayOneShot(slide[Random.Range(0, slide.Length - 1)]); } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter