Hi there, I’ve been trying to get FMOD to play different sound clips depending on the character’s surface they are standing on. Right now, I’ve decided to use a Scriptable Object (SO) to handle this.
In theory, the collider that contains a tag that displays which material the player is standing on has a SO that contains this code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using FMOD.Studio;
using FMODUnity;
[CreateAssetMenu(fileName = “Surfaces”, menuName = “ScriptableObjects/SurfaceScriptableObject”, order = 1)]
public class SurfaceScriptables : ScriptableObject
{
EventInstance playerWalkingOnConcreteFlat;
EventInstance playerWalkingOnWoodFlat;
void Start()
{
playerWalkingOnConcreteFlat = AudioManager.instance.CreateEventInstance(FModEvents.instance.PlayerWalkingOnConcreteFlat);
playerWalkingOnWoodFlat = AudioManager.instance.CreateEventInstance(FModEvents.instance.PlayerWalkingOnWoodFlat);
}
void OnTriggerStay2D(Collider2D col)
{
if (col.tag == "Player")
{
{
aSoundInstance = RuntimeManager.CreateInstance(aSound);
aSoundInstance.start();
}
}
}
void OnTriggerExit2D(Collider2D col)
{
aSoundInstance.stop(FMOD.Studio.STOP_MODE.ALLOWFADEOUT);
}
}
(Doesn’t compile yet)
And this code is supposed to take whatever audio file is inserted into the SO and insert it into the code block, then play the code to loop his walking sound, before terminating after he leaves the material OR stops moving.
So far I have no idea how to execute this. It should be pretty simple in theory.
- SO checks when the player collides with it.
- Each SO for the corresponding material has an audio file containing the walk and run sounds.
- When it detects a collision and the player moving faster than 0.1 speed, it should play the footstep sound, and stop when the player moves slower than 0.1, OR leaves the collider.