I'm working on a demo audio project in Unity 5 and coming across some issues. My goal is to assign the value of currentHealth (which is contained inside a separate "PlayerHealth" script) to a parameter in FMOD that modulates the music (makes it more intense) as the health of the player decreases. I am not a programmer by any means, but have been forced to get my hands dirty to implement the music in Unity 5.
HealthParam.setValue (PlayerHealth.currentHealth);
This line of code is making Unity unhappy. I've gathered it might have something to do with the difference between static and instance members, but again I'm not a programmer and really don't know how to delve into the weeds on this.
The errors are:
"Argument
#1' cannot convert
object' expression to type `float'""The best overloaded method match for `FMOD.Studio.ParameterInstance.setValue(float)' has some invalid arguments"
"An object reference is required to access non-static member `PlayerHealth.currentHealth'"
Here is the Script:
using UnityEngine;
using System.Collections;
public class MusicManager : MonoBehaviour
{
public int startingHealth = 100;
public int currentHealth;
public PlayerHealth playerHealth;
GameObject player;
[FMODUnity.EventRef]
public string ScaryMusic = "event:/ZombunnyHorrorMusic";
FMOD.Studio.EventInstance MusicEv;
FMOD.Studio.ParameterInstance HealthParam;
void awake()
{
// player = GameObject.FindGameObjectWithTag ("Player");
// playerHealth = player.GetComponent <PlayerHealth> ();
}
void Start ()
{
MusicEv = FMODUnity.RuntimeManager.CreateInstance (ScaryMusic);
MusicEv.getParameter ("Health", out HealthParam);
MusicEv.start ();
}
void update()
{
// currentHealth = Mathf.Abs (PlayerHealth.currentHealth);
HealthParam.setValue (PlayerHealth.currentHealth);
}
void OnDestroy ()
{
MusicEv.stop (FMOD.Studio.STOP_MODE.IMMEDIATE);
}
}