car's sound was updated: fmod modulation, integration into Unity and fixing the overall sound through a different script
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
using UnityEngine;
|
||||
using FMOD.Studio;
|
||||
|
||||
public class CarAudioController : MonoBehaviour
|
||||
{
|
||||
private EventInstance carMovementInstance;
|
||||
private FirstPersonOcclusion occlusion;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
//Debug.LogError("AUDIO MANAGER:");
|
||||
//Debug.LogError(AudioManager.Instance);
|
||||
//Debug.LogError("FMOD EVENTS INSTANCE:");
|
||||
//Debug.LogError(FMODEvents.Instance);
|
||||
//Debug.LogError("Car Simple Driving:");
|
||||
//Debug.LogError(FMODEvents.Instance.BoltCarSimpleDriving);
|
||||
carMovementInstance = AudioManager.Instance.CreateInstance(FMODEvents.Instance.CarModulatedDriving);
|
||||
carMovementInstance.setParameterByName("RPM", 1450);
|
||||
carMovementInstance.setParameterByName("Load", 0);
|
||||
carMovementInstance.set3DAttributes(FMODUnity.RuntimeUtils.To3DAttributes(gameObject));
|
||||
|
||||
occlusion = GetComponent<FirstPersonOcclusion>();
|
||||
if (occlusion != null)
|
||||
occlusion.InitialiseWithInstance(carMovementInstance);
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
carMovementInstance.start();
|
||||
AudioManager.Instance.SetGlobalParameter("CarPassengerLogic", 0.0f); //change the value of the global parameter in FMOD, initial value
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
// Always update 3D position to follow the car model transform
|
||||
carMovementInstance.set3DAttributes(FMODUnity.RuntimeUtils.To3DAttributes(gameObject));
|
||||
}
|
||||
|
||||
// These methods are called externally by CarDrivingRoutine
|
||||
public void SetRPM(float value)
|
||||
{
|
||||
carMovementInstance.setParameterByName("RPM", value);
|
||||
}
|
||||
|
||||
public void PlayStopSound()
|
||||
{
|
||||
carMovementInstance.getParameterByName("RPM", out float currentRPM);
|
||||
|
||||
if (currentRPM == 475)
|
||||
{
|
||||
AudioManager.Instance.PlayAttachedInstance(FMODEvents.Instance.BoltCarStopSound, gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user