- Home /
Variable won't update within a certain function
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.
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().
The 'outside' boolean switches between true and false depending on the player's position. This line
print("Footstep Transition: " + (outside ? "Outside" : "Inside"));
allows me to check that it is updated normally and works fine. I assign 'isOutside' to 'outside' which means isOutside should now update according to the player's position.
Now if i print to console within the Update() function using this line :
print("isOutside Check: " + (isOutside ? "True" : "False"));
, I can confirm that isOutside switches normally between true and false and works fine. But the same print line within the OnFootstep() function shows that 'isOutside' is not being updated at all and doesn't switch between true and false. And i've no idea why....
Anyone has any idea how I could pass that value? 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.