59 lines
1.4 KiB
C#
59 lines
1.4 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
#if FMOD_AVAILABLE
|
|
using FMOD;
|
|
using FMODUnity;
|
|
#endif
|
|
|
|
[RequireComponent(typeof(Rigidbody))]
|
|
public class OnCollideSound : MonoBehaviour
|
|
{
|
|
#if FMOD_AVAILABLE
|
|
[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>();
|
|
}
|
|
|
|
private void OnCollisionEnter(Collision collision)
|
|
{
|
|
if (_rigidbody.velocity.magnitude >= minVelocity)
|
|
{
|
|
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);
|
|
UnityEngine.Debug.Log(gameObject.name);
|
|
}
|
|
|
|
_specialCase = false;
|
|
}
|
|
}
|
|
#endif
|
|
}
|