UP-Viagg-io/Viagg-io/Assets/Scripts/Audio/OnCollideSound.cs

57 lines
1.4 KiB
C#
Raw Normal View History

2024-11-21 21:29:58 +01:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
2025-01-07 17:33:31 +01:00
#if FMOD_AVAILABLE
using FMOD;
2024-11-21 21:29:58 +01:00
using FMODUnity;
2025-01-07 17:33:31 +01:00
#endif
2024-11-21 21:29:58 +01:00
[RequireComponent(typeof(Rigidbody))]
2024-11-21 21:29:58 +01:00
public class OnCollideSound : MonoBehaviour
{
[SerializeField]
EventReference soundRef;
[SerializeField]
float minVelocity = 0.1f;
[SerializeField]
List<string> specialTags = new List<string>();
[SerializeField]
List<EventReference> specialSounds = new List<EventReference>();
private bool _specialCase = false;
private Rigidbody _rigidbody;
private void Start()
{
_rigidbody = GetComponent<Rigidbody>();
}
2024-11-21 21:29:58 +01:00
private void OnCollisionEnter(Collision collision)
{
if (_rigidbody.velocity.magnitude >= minVelocity)
2024-11-21 21:29:58 +01:00
{
for(int i=0; i<specialTags.Count; i++)
{
if (collision.transform.tag == specialTags[i])
{
RuntimeManager.PlayOneShot(specialSounds[i], transform.position);
_specialCase = true;
break;
}
}
if (!_specialCase)
{
// Play default collide sound
RuntimeManager.PlayOneShot(soundRef, transform.position);
2025-01-07 17:33:31 +01:00
UnityEngine.Debug.Log(gameObject.name);
}
_specialCase = false;
2024-11-21 21:29:58 +01:00
}
}
}