Unity - Playing an Fmod Event on an Animation's Keyframe


(Renato777) #1

I have Fmod Studio integrated with Unity and I’m now trying to play an Fmod Studio Event on an animation’s keyframe.

On the Animation’s timeline I set a keyframe to enable the following script:

using UnityEngine;
using System.Collections;
using FMOD.Studio;

public class AnimationPlayFmodSound : MonoBehaviour {

	void OnEnable () {
		FMOD_StudioSystem.instance.PlayOneShot ("event:/Resources/FX/fx_column_effect", transform.position);		
	}
}

I thought it should play only when the script is enabled, but apparently the event plays as soon as I start the game (before the animation occurs). What am I doing wrong here?


(Jussi Elsilä) #2

This works for me:

using UnityEngine;
using System.Collections;

public class SoundEvent : MonoBehaviour {

public FMODAsset A_EventSound;
	
public void PlaySound (FMODAsset A_EventSound) {
		if(A_EventSound != null)
		{
			FMOD_StudioSystem.instance.PlayOneShot(A_EventSound, transform.position);
		}
		else
		{
			Debug.LogError("EventSound is null");
		}
		
	}
}

The script is attached to the root of the GameObject (model).


(Renato777) #3

It works! Thanks a lot!