Change event in runtime

hi all, congratulations for fmod :100:, i am a beginner entering the world of fmod. I am programming a drum machine, I wanted to know how I can change event in runtime? I use version 2.02.05
i tried to do

public class playb : MonoBehaviour
{     private FMOD.Studio.EventInstance instance;
      public string[] sample;
     int ind;

  void selectSAMPLE()
  {instance = FMODUnity.RuntimeManager.CreateInstance(sample[ind]);}

  void PLAY()

the goal is to change samples while it is in runtime …
I created 1 event for each sample and I would like … is this correct?
but I don’t know why the code doesn’t work :thinking:

no response??

That should be enough to change the event at runtime, though I can see a couple of reasons why this script alone wouldn’t result in any audio playing back. To start with, are you calling these methods anywhere? For example, a fixed update loop that calls these functions would be a good start for a drum machine

int timeCounter = 0;
private void FixedUpdate() // Called 50 times per second
    if(timeCounter++ == 0)
        ind = (ind + 1) % sample.Length;

    timeCounter = timeCounter % 10;

Also, you will need to make sure that elements in your sample array are the correct string paths, for example “event:/Music/Kick”, “event:/Music/Snare” etc. You can get these by right clicking on the event in FMOD Studio and selecting “Copy Path”.
If you haven’t already, I would recommend following with the Unity Integration Tutorial to get you started with Unity FMOD scripting if you are new to FMOD / Unity / Scripting in general.