0

I'm currently trying to develop my first mini game (a VR musical experience).

I'm trying to have the value of a slider control an FMOD parameter, but nothing happens. Plus the function does not show in the On Value Changed of the slider...

I'm already using that slider to control the transparency of a material and if I try changing the FMOD parameter manually in the inspector it works just fine.

Here is the script:

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

public class FMODParameters : MonoBehaviour
{

    FMODUnity.StudioEventEmitter changeVolume;

    FMOD.Studio.EventInstance bass;

    public string bassVolumeParameter;

    public Slider slider;

    void Start()
    {
        changeVolume = GetComponent<FMODUnity.StudioEventEmitter>();

        bass = FMODUnity.RuntimeManager.CreateInstance("event:/Beat/2D/2D Bass");

        slider = GetComponent<Slider>();

      
    }

    // Update is called once per frame
    void Update()
    {
        SetBassVolume();
    }

    void SetBassVolume()
    {
        bass.setParameterByName(bassVolumeParameter, slider.value / 250);
    }
}

Thanks in advance for the help! :)

1 Answer 1

0

The problem is that you have to add the function in the onValueChanged () listener. To do it:

  • Select the gameObject with the Slider component;
  • Click the "+" button in the OnValueChanged () listener below;
  • In the empty field, under "Runtime only", drag the gameObject with this script;
  • Click the box that now has the name "No Function";
  • In the component list, place the cursor over the script name, and under the "Dynamic parameters" category, the SetBassVolume () method.

But first you should tweak the method a bit, like so:

void SetBassVolume(float _value)
{
    bass.setParameterByName(bassVolumeParameter, _value / 250);
}

Good work!

Sign up to request clarification or add additional context in comments.

6 Comments

Thanks for replying! So I did drag the gameObject that has the script on it into the empty field, but then when I look for it in the "No function" section, I can find it but only shows static parameters.
Also I'm not sure what you mean by tweaking the method, isn't it how I've written it already?
Oh I’m sorry. An error occurred probably during the saving of the answer. Now you can find the dynamic parameter.
Now it gives me this error: CS7036: There is no argument given that corresponds to the required formal parameter '_value' of 'FMODParameters.SetBassVolume(float)' on line 33 (the update method)
this is how I updated the script, is there anything I should put in the parenthesis in the SetBassVolume(); function? Feel free to redirect me to any documentation I should look at in order to understand this. Thanks a lot for taking the time by the way! ------------------------------------------------- void Update() { SetBassVolume(); } void SetBassVolume(float _value) { bass.setParameterByName(bassVolumeParameter, _value / 250); } }
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.