45 lines
910 B
C#
45 lines
910 B
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class SoundEmitter : MonoBehaviour
|
|
{
|
|
public Sound Sound;
|
|
public SoundPlayer SoundPlayer;
|
|
|
|
public bool PlayOnlyOnce = false;
|
|
public bool MuteOtherSound = false;
|
|
|
|
private bool _played = false;
|
|
|
|
private void Awake()
|
|
{
|
|
if (Sound.PlayOnAwake)
|
|
{
|
|
Play();
|
|
}
|
|
}
|
|
|
|
[ContextMenu("debug")]
|
|
public void Play()
|
|
{
|
|
if (PlayOnlyOnce && _played)
|
|
return;
|
|
|
|
if (MuteOtherSound)
|
|
{
|
|
var otherSounds = FindObjectsOfType<SoundPlayer>();
|
|
foreach (var sound in otherSounds)
|
|
{
|
|
sound.Mute(Sound.Clip.length);
|
|
}
|
|
}
|
|
|
|
var s = Instantiate(SoundPlayer, transform.position, Quaternion.identity);
|
|
s.Play(Sound);
|
|
|
|
_played = true;
|
|
}
|
|
}
|