List of gameobjects attached to single object

Hey Guys, I’m making a 2D game. In some point I want that when my character goes through some position I want to ‘shot him’ with another game object. In other words, I got a hidden GameObject, and when my player walks into some kind of “detector” that hidden GameObject will start moving in the same direction my player is. So, if it touches him, he’ll die.

You will see what I mean clearly in this video.

Check seconds 0.10 and 0.15. That’s exactly what i want to do.

The issue is that i got that working, but every “detector” (in my case a detector is a BoxCollider2D wich is Trigger) can only have one gameObject (one spike) attached to it.

public class ActivateSlider : MonoBehaviour {
 
    public EnemDesplazController slider; //I have to attach the slider on unity
 
    void OnTriggerEnter2D(Collider2D col){
       if (col.name == "Character") {
            slider.activated = true;
                     //this will go to my spike and activate it, so it'll start moving.
            this.GetComponent<BoxCollider2D>().enabled = false;
       }
    }
}
 
public class EnemDesplazController : MonoBehaviour {
    public bool activated = false;
        //Got some more variables here but they are related 
        //to the movement of the spike
 
    // Update is called once per frame
    void Update () {
 
       if (activated) {          
                    //Code that moves my spike. I ve already done it.   
       }
    }
 
     void OnTriggerEnter2D (Collider2D col){
         Respawn rsp = new Respawn ();
         rsp.OnTriggerEnter2D (col);
             //This method kills my player when the gameobject (spike) touches it.
    }
}

So the question is, can I attach multiple objects to a detector? I mean, I’d like to do smething like this:

public class ActivateSlider : MonoBehaviour {

    public EnemDesplazController[] sliderLst; //And then on unity i will drag and drop every single spike.

Maybe there’s a better way to do what I want. I’ll be listening your advices.

I wouldn’t attach the detector and the spike at all. Just have the detector Instantiate() a spike from a Prefab, which will Destroy() itself when it’s done.

You can have 2 or more sprites in a prefab laid out how you need them to be.