68 lines
1.1 KiB
C#
68 lines
1.1 KiB
C#
using UnityEngine;
|
|
|
|
public class SoundTriggerManager : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
private AudioSource audioSource;
|
|
|
|
[Space(10f)]
|
|
[SerializeField]
|
|
private bool OdtwarzajNaStart;
|
|
|
|
[SerializeField]
|
|
private float OpoznienieNaStartWSek;
|
|
|
|
[Space(10f)]
|
|
[SerializeField]
|
|
private bool Powtarzanie;
|
|
|
|
[SerializeField]
|
|
private float CzasPowtarzaniaWSek;
|
|
|
|
[Space(10f)]
|
|
[SerializeField]
|
|
private float OpoznienieTriggeraWSek;
|
|
|
|
private bool soundPlayed;
|
|
|
|
private void Start()
|
|
{
|
|
if (OdtwarzajNaStart)
|
|
{
|
|
if (!Powtarzanie)
|
|
{
|
|
audioSource.PlayDelayed(OpoznienieNaStartWSek);
|
|
}
|
|
else
|
|
{
|
|
Invoke("RepeatDelayed", OpoznienieNaStartWSek);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void OnTriggerEnter(Collider other)
|
|
{
|
|
if (!soundPlayed && !Powtarzanie)
|
|
{
|
|
audioSource.PlayDelayed(OpoznienieTriggeraWSek);
|
|
soundPlayed = true;
|
|
}
|
|
}
|
|
|
|
private void RepeatDelayed()
|
|
{
|
|
InvokeRepeating("ASPlay", 0.1f, audioSource.clip.length + CzasPowtarzaniaWSek);
|
|
}
|
|
|
|
private void ASPlay()
|
|
{
|
|
audioSource.Play();
|
|
}
|
|
|
|
private void OnDrawGizmos()
|
|
{
|
|
Gizmos.color = Color.yellow;
|
|
Gizmos.DrawWireCube(base.transform.position, base.gameObject.transform.localScale);
|
|
}
|
|
}
|