How do I set a paremeter, or stop an event instance from script B, when script A has the instance of the event?
Is there a way to allow a game designer to drag and drop an event instance from a separate script into a unity inspector? I was unable to get this working.
Of course I can use GetComponent, but that means we have to code this every time and it’s not scalable.
There are many ways you could do this. The easiest I can think of would be to create a static method in Script A that stops or sets a parameter on an event instance:
public class ScriptA
{
static EventInstance eventInstance;
public static void StopEventInstance()
{
eventInstance.stop(FMOD.Studio.STOP_MODE.IMMEDIATE);
}
}
class ScriptB
{
void Stop()
{
ScriptA.StopEventInstance();
}
}
You can drag EventReference path from the Event Browser into an FMODUnity.EventReference field in the inspector, so you can look at “Assets\Plugins\FMOD\src\Editor\EventBrowser.cs” for a reference. I think implementing Drag and Drop in the Unity Editor is a little out of scope for the forums, but here is a Unity Editor tutorial on how this works.