# FMOD-Unity 5 Parameter Trigger

**URL:** <https://qa.fmod.com/t/fmod-unity-5-parameter-trigger/12608>\
**Category:** FMOD Studio\
**Created:** [July 20, 2016, 10:45pm UTC](https://qa.fmod.com/t/fmod-unity-5-parameter-trigger/12608 "2016-07-20T22:45:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![seriallab](https://avatars.discourse-cdn.com/v4/letter/s/5f8ce5/32.png) [@seriallab](https://qa.fmod.com/u/seriallab)\
**Post date:** [July 20, 2016, 10:45pm UTC](https://qa.fmod.com/t/fmod-unity-5-parameter-trigger/12608/1 "2016-07-20T22:45:39Z")

</div>

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;
    }
}
}
```

---

<div class="post-metadata">

**Author:** ![nick1](https://avatars.discourse-cdn.com/v4/letter/n/47e85d/32.png) [@nick1](https://qa.fmod.com/u/nick1)\
**Post date:** [July 21, 2016, 1:23am UTC](https://qa.fmod.com/t/fmod-unity-5-parameter-trigger/12608/2 "2016-07-21T01:23:26Z")

</div>

This is a generic C# coding error. You’ve put the functions **OnTriggerEnter**  **OnTriggerExit** inside another function which is not valid code.

```
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(); 
            }

              

            footstepTimer += Time.deltaTime;
        }
    }

    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);
        }
    }
}
```

---

<div class="post-metadata">

**Author:** ![seriallab](https://avatars.discourse-cdn.com/v4/letter/s/5f8ce5/32.png) [@seriallab](https://qa.fmod.com/u/seriallab)\
**Post date:** [July 21, 2016, 8:14pm UTC](https://qa.fmod.com/t/fmod-unity-5-parameter-trigger/12608/3 "2016-07-21T20:14:08Z")

</div>

> [@](#):
>
> This is a generic C# coding error. You’ve put the functions **OnTriggerEnter**  **OnTriggerExit** inside another function which is not valid code.
> 
> ```
> 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(); 
> }
> 
>               
> 
> footstepTimer += Time.deltaTime;
> }
> }
> 
> 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);
> }
> }
> }
> 
> ```

Thank you Nicholas. I suspected this may be the issue and am trying to work out how to untangle this.

---

<div class="post-metadata">

**Author:** ![seriallab](https://avatars.discourse-cdn.com/v4/letter/s/5f8ce5/32.png) [@seriallab](https://qa.fmod.com/u/seriallab)\
**Post date:** [July 22, 2016, 10:58pm UTC](https://qa.fmod.com/t/fmod-unity-5-parameter-trigger/12608/4 "2016-07-22T22:58:53Z")

</div>

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.
