Im trying to set the volume of a sound effect to a parameter that changes depending on how fast one of my objects is moving (the puck specifically.) I have the parameter range within FMOD set to 0-1, however I did try changing this but it didnt work out.
script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using FMOD.Studio;
using FMODUnity;
public class FMODParamHandler : MonoBehaviour
{
//object references
public Rigidbody2D puckRb;
//reference to FMODEventsHolder instance
private FMODEventsHolder eventsHolder;
//event references
public EventReference puck_HitPaddle;
public EventReference puck_BounceWall;
//event instances
private EventInstance puckHitPaddleInstance;
private EventInstance puckBounceWallInstance;
public float puckVelocityParameter;
void Start()
{
//Initialize the reference to FMODEventsHolder
eventsHolder = FMODEventsHolder.instance;
//Initialize EventInstances
puckHitPaddleInstance = FMODUnity.RuntimeManager.CreateInstance(eventsHolder.puck_HitPaddle);
puckHitPaddleInstance = FMODUnity.RuntimeManager.CreateInstance(eventsHolder.puck_BounceWall);
}
void Update()
{
//puckVelocity set
Vector2 puckVelocity = puckRb.velocity;
float puckSpeed = puckVelocity.magnitude;
puckVelocityParameter = puckSpeed;
puckHitPaddleInstance.setParameterByName("puckVelocity", puckSpeed);
puckBounceWallInstance.setParameterByName("puckVelocity", puckSpeed);
}
}