rabidus-test/Assets/SoundPlayer.cs

31 lines
655 B
C#
Raw Normal View History

2023-10-09 16:51:27 +03:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SoundPlayer : MonoBehaviour
{
private AudioSource source;
private void Awake()
{
source = gameObject.AddComponent<AudioSource>();
}
public void Play(Sound sound)
{
source.clip = sound.Clip;
source.volume = sound.Volume;
source.pitch = sound.Pitch;
source.priority = sound.Priority;
source.playOnAwake = sound.PlayOnAwake;
source.loop = sound.Loop;
2023-10-09 17:30:55 +03:00
source.spatialBlend = sound.Zone;
2023-10-09 16:51:27 +03:00
source.Play();
}
2023-10-27 18:07:01 +03:00
public void Stop()
{
source.Stop();
}
2023-10-09 16:51:27 +03:00
}