简体   繁体   English

FMOD 参数不通过 C# 脚本更改

[英]FMOD parameter not changing through C# script

I'm currently trying to develop my first mini game (a VR musical experience).我目前正在尝试开发我的第一个迷你游戏(VR 音乐体验)。

I'm trying to have the value of a slider control an FMOD parameter, but nothing happens.我试图让滑块控制 FMOD 参数的值,但没有任何反应。 Plus the function does not show in the On Value Changed of the slider...另外,该功能未显示在滑块的 On Value Changed 中...

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.我已经在使用该滑块来控制材质的透明度,如果我尝试在检查器中手动更改 FMOD 参数,它就可以正常工作。

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!在此先感谢您的帮助! :) :)

The problem is that you have to add the function in the onValueChanged () listener.问题是您必须在 onValueChanged () 侦听器中添加该函数。 To do it:去做吧:

  • Select the gameObject with the Slider component;选择带有 Slider 组件的游戏对象;
  • Click the "+" button in the OnValueChanged () listener below;点击下方OnValueChanged()监听器中的“+”按钮;
  • 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.在组件列表中,将光标放在脚本名称上,然后在“动态参数”类别下,SetBassVolume() 方法。

But first you should tweak the method a bit, like so:但首先你应该稍微调整一下方法,如下所示:

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

Good work!干得好!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM