Playing a looping event at start & changing a parameter with player footsteps?

(Joel Douglas) #1


I’m pretty new to scripting, Unity & FMOD so hoping someone can help me out.
Basically what I’m trying to do is create a scene in Unity in which the player creates music by moving around the environment. One of the features I’m trying to make is having the player’s footsteps be randomised piano notes.

I’ve managed to get a basic footstep script working so the Footsteps event plays when the player moves, but I want all the sounds to be tempo-synced. The way I am trying to do this is by having the Footsteps play on a constant loop, and when the player moves it changes a parameter controlling volume - so the piano sounds can be heard only when the player moves.

I have an Event Emitter on the player which plays the event from object start with an initial parameter value of 0 (off), but I can’t get my script to interact with the parameter value?
This is the script I have attempted, but doesn’t work:

public string feet = "event:/Footsteps";
public FMOD.Studio.EventInstance walking;
public FMOD.Studio.ParameterInstance movement;
bool playerismoving;

void Start () {
	walking = FMODUnity.RuntimeManager.CreateInstance(feet);
	walking.getParameter ("Walking", out movement);
	walking.start ();


void Update ()
	if (Input.GetAxis ("Vertical") >= 0.01f || Input.GetAxis ("Horizontal") >= 0.01f || Input.GetAxis ("Vertical") <= -0.01f || Input.GetAxis ("Horizontal") <= -0.01f) {
		Debug.Log ("Player is moving!");
		playerismoving = true;
	} else if (Input.GetAxis ("Vertical") == 0f || Input.GetAxis ("Horizontal") == 0f) {
		Debug.Log ("Player isn't moving");
		playerismoving = false;

void PlayFootsteps ()
	if (playerismoving == true); 

	if (playerismoving == false); 

Can anyone help me achieve what I want to do? Any help would be hugely appreciated.

(リチャード清水) #2

Hi Joel,

You’ve created the PlayFootsteps() function but haven’t actually called it in Update(). Try adding “PlayFootsteps();” to the end of the if and elseif statements.