Help with Parameters

Hello wonderful people of the FMod community.

I’m having some trouble with a simple script.
I’ve got an Fmod event called ‘Ambience’ with a Parameter called ‘Height’ which adds wind sounds to the ambience.
I want the ‘Height’ to relate to the Y axis position of my player in Unity. Can someone pls help me with this script?


I am no programmer, but I’ll give it a try.
Basically what you need to do is to get the height value of your player from the Y position of the Transform component on your Player GameObject. Then you should pass that value to the “Height” parameter in your FMOD event.
Here’s how I would do it:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class YourScript : MonoBehaviour
    public Transform myTransform;

    void Start()
        myTransform = GetComponent<Transform>();

    void FixedUpdate()
        //you can probably do this in Update() as well
        float playerHeight = myTransform.position.y;

        //check the value on the console

        //apply the value to FMOD parameter
        var emitter = GetComponent<FMODUnity.StudioEventEmitter>();
        emitter.SetParameter("Height", playerHeight);

Maybe there’s a more efficient way to do it, but it should work.

That looks good, but you can cache the Studio Event Emitter in Start() instead of calling GetComponent() in FixedUpdate() :slight_smile:

Right, that makes sense. Thanks!