Then, depending on how you manage your instances, you will have to make those instances subscribe to the OnRepeat event. Here here an example with 2 simple scripts : a Spawner and a Spawnee
// Spawnee.cs
public class Spawnee : MonoBehaviour
{
public void SayMyName()
{
Debug.Log( name );
}
}
// Spawner.cs
public class Spawner : MonoBehaviour
{
// Drag & drop the gameObject holding the Repeater script in the inspector
public Repeater Repeater;
private void Spawn()
{
Spawnee instance = Instantiate( spawneePrefab ) ;
Repeater.OnRepeat.AddListener( instance.SayMyName ) ;
}
}
Thanks for this! I’ve not used event systems before, so this was super helpful.
I altered it a bit, so the spawnee’s prefab adds the listener to itself when it’s created, so both spawned ones and those in the scene when it starts both have it. Totally working now!