Hey guys,
Not sure this is exactly the right forum for this but it involves FMOD and Unity so i figured i’d put it here.
I’m having a bit of fun with the Angry Bots project and the FMOD intergration provided by Sound Librarian http://www.soundlibrarian.com/uploads/3 … torial.pdf
I’ve been trying to automate the footsteps so that they sound different depending on whether the player is outside or inside. Here’s my code so far
#pragma strict
class FootstepHandler extends MonoBehaviour
{
enum FootType
{
Player,
Mech,
Spider
}
public var audioSource : AudioSource;
public var footType : FootType;
private var evt : FMOD.Studio.EventInstance;
private var param : FMOD.Studio.ParameterInstance;
private var attributes : FMOD.Studio._3D_ATTRIBUTES;
public var isOutside = true;
public var physicMaterial : PhysicMaterial;
private var eventPath : String;
static var sInstance : FootstepHandler = null;
static function instance() : FootstepHandler
{
return sInstance;
}
function Awake()
{
sInstance = this;
}
function OnCollisionEnter (collisionInfo : Collision)
{
physicMaterial = collisionInfo.collider.sharedMaterial;
}
function OnFootstep ()
{
switch (footType)
{
case FootType.Player:
eventPath = MaterialImpactManager.GetPlayerFootstepSound(physicMaterial);
break;
case FootType.Mech:
eventPath = MaterialImpactManager.GetMechFootstepSound(physicMaterial);
break;
case FootType.Spider:
eventPath = MaterialImpactManager.GetSpiderFootstepSound(physicMaterial);
break;
}
if (!String.IsNullOrEmpty(eventPath))
evt = FMOD_StudioSystem.instance.GetEvent(eventPath);
attributes = FMOD.Studio.UnityUtil.to3DAttributes(transform.position);
evt.set3DAttributes(attributes);
evt.getParameter("Wet", param);
param.setValue(isOutside ? 1.0f : 0.0f);
evt.start();
evt.release();
}
public function setOutside(outside : boolean)
{
isOutside = outside;
print("Footstep Transition: " + (outside ? "Outside" : "Inside"));
}
}
Angry Bots is using ‘MoodBoxes’ to trigger changes when the player walks through them. In the script above, the function setOutside() is using data from those MoodBoxes (in another script) to switch between Inside and Outside. The value is assigned to a boolean variable called isOutside, and that value is then used to modify the FMOD parameter within the OnFootstep() function (which is triggering the FMOD event).
Here’s my problem though: the isOutside variable won’t update within the OnFootstep() function. It works fine within setOutside(), and Update() for example but not in OnFootstep(). I checked using the console.
Anyone has any idea how I could pass that value to the right function, or do anything to make it work?
Hopefully it’s something quite easy or obvious i’m missing, but I’ve been pulling my hair out on this one and here’s hoping someone can help.
Thanks in advance and let me know if you need any more detail.