Hello, I can’t solve this problem, I’ve made FMOD parameter “health” (range 0-100), and I want it to link with Player Health in Unity, so when Player’s health drops below 30% it will trigger FMOD parameter “Health” with simple low filter cutoff. When I’m implement code into Unity, it gets me the following errors, please check my script, I’ve added comments:
using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
using FMOD.Studio;
public class MusicControl : MonoBehaviour {
[FMODUnity.EventRef]
public string explosion = "event:/EXPLOSION";
[FMODUnity.EventRef]
public string shoot = "event:/SHOOT SOUND";
[FMODUnity.EventRef]
public string menuMusic = "event:/MENU MUSIC";
int val;
public FMOD.Studio.EventInstance musicEv;
public FMOD.Studio.ParameterInstance musicPar;
void Start()
{
}
//music for menu, I'm call this function when my stage starts(menu game)
public void MenuMusic()
{
musicEv = FMODUnity.RuntimeManager.CreateInstance(menuMusic);
musicEv.start();
}
//music for level 1, I'm call this function when my stage starts(level game)
public void LevelMusic()
{
musicEv = FMODUnity.RuntimeManager.CreateInstance(menuMusic);
musicEv.setParameterValue("FIGHT MUSIC", 100f);
musicEv.getParameter("HEALTH", out musicPar);
musicPar.setValue(100);
musicEv.start();
}
//I'm call this function when stages is close up
public void StopMusic()
{
musicEv.stop(FMOD.Studio.STOP_MODE.IMMEDIATE);
}
// I'm take current Health from Player script
void Update()
val = GameObject.Find("Player").GetComponent<Player>().stats.curHealth;
musicPar.setValue(val); //Unity gives me an error - NullReferenceException: Object reference not set to an instance of an object MusicControl.Update () (at Assets/MusicControl.cs:147)
}
}