Iterative list assigner with game objects

So here’s my current code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MapGenerator : MonoBehaviour {

    public int roomLimit;

    public float timeDelay = 1f;

    public Spawner roomMaker; // Links to spawner script
    public GameObject middle;

    [SerializeField]
    public List<GameObject> spawners = new List<GameObject>();

    private int listLength;

    private int i;

    private GameObject clear;

    void Update() {
        MiddleChecker();
        Adder();
        Invoke("Generator", timeDelay);
    }

    void MiddleChecker() {
        middle.SetActive(false);
        middle.SetActive(true);
    }

    void Adder() {
        spawners.Clear();
        foreach(GameObject temp in GameObject.FindGameObjectsWithTag("SpawnPoint")) {
            spawners.Add(temp);
        }
    }

    void Generator() {
        roomMaker.spawner = spawners[4];
        roomMaker.Spawn();
    }
}

What I am trying to accomplish is the list ‘spawners’ has identical game objects (but in different coordinates) in it. I then want the code to assign each game object to the spawner variable in the ‘Spawner’ script which I am doing through roomMaker. Then after I have assigned the game object to the variable, I want the Spawn() class in the Spawner script to be called. After that, it repeats for the next object in the list. How can I go about doing this?

Thanks!

OK, Which object do you want to add to the roomMaker varaible? - you didn’t answer that. And what object is the Spawner script attached to, your spawner objects? IF it is, and you want to execute a function the script on it you can do this (and I’m assuming you want to add every spawner to the roomMaker variable).

  foreach(GameObject temp in GameObject.FindGameObjectsWithTag("SpawnPoint")) {
         spawners.Add(temp);
         temp.GetComponent<Spawner>().Spawn();
         roomMaker.spawner = temp;
  }

Hi again, @JackAshwell ! Well, you need to be clear about what you want:

  1. you want references to all your objects into a list named spawners - OK, you are doing that.
  2. here is where it gets fuzzy: You want to assign each of those to a variable in the roomMaker class? I don’t see where you are doing that.
  3. Then you want to execute a function in a Spawner script? Where is that script?