Hello, I am an audio designer and new to C# so please excuse any mistakes I have made in my code.
I have a simple first person scene in Unity 5 and I am working on this footstep script so as the camera moves across the terrain the steps will trigger. I was able to get a single event to trigger but when I updated the script to include the parameter I am getting all sort of errors. This is one of the errors “error CS1547: Keyword `void’ cannot be used in this context”
Any tips on how to clean this up would be very much appreciated.
using UnityEngine;
using System.Collections;
public class Footsteps : MonoBehaviour {
[FMODUnity.EventRef] //Declare FMOD event (can also declare snapshots and parameters)
private FMOD.Studio.EventInstance footsteps;
private FMOD.Studio.ParameterInstance Material;
float footstepTimer = 0.0f;
Vector3 lastPos = new Vector3(0, 0, 0);
// Update is called once per frame
void Update () {
bool isMoving = false;
Transform thisTransform = (Transform)GetComponent("Transform");
if (lastPos.x != thisTransform.position.x || lastPos.y != thisTransform.position.y)
{
isMoving = true;
}
lastPos = thisTransform.position;
if (/*Input.GetAxis("Horizontal") != 0.0f || Input.GetAxis("Vertical") != 0.0f ||*/ isMoving)
{
if (footstepTimer > 0.40f)
{
footsteps = FMOD_StudioSystem.instance.GetEvent ("event:/footsteps");
if (footsteps.getParameter ("Material", out Material) != FMOD.RESULT.OK) {
Debug.LogError ("Can't find Material parameter on the event");
}
musicEvent.start();
}
void OnTriggerEnter (Collider other) {
if (other.tag == "Grass") {
Material.setValue (1);
}
if (other.tag == "Wood") {
Material.setValue (2);
}
if (other.tag == "Dirt") {
Material.setValue (3);
}
void OnTriggerExit (Collider other) {
if (other.tag == "Grass" || other.tag == "Wood" || other.tag == "Dirt") {
Material.setValue (0);
}
footstepTimer += Time.deltaTime;
}
}
}
Thanks again Nicholas! Your help is much appreciated. I was able to get it all working with your code fix and after realizing I was using the old FMOD_StudioSystem.instance.GetEvent. I checked out the 2.0 migration doc and see I needed to use the FMODUnity.RuntimeManager.CreateInstance.