personally I’d use:
int spawnCount = spawnPoints.Length - 1
rather than:
int spawnCount = 20
also, make sure that spawnPoints has actually been initialized AND populated based on the fact that it’s public in a MonoBehaviour, it is /possible/ that it’s initialized in the editor…
also spawnCount > 0 means the initial entry will never be used
From the look of your screenshot, the object which you’re spawning is the same as the object to which this script is attached? That sounds wrong, and will lead to an exponential growth in the number of spawners (the new clones of which won’t have any spawnobjects assigned)…
I would suggest that you have a single spawner manager object to wbich this script is attached, but it should not also be attached to individual spawnpoints.
If that does not resolve your index out of range, make liberal use of Debug.Logs to print values of each of your variables.
Using Random.Range with ints makes the max value be inclusive; that means that if you have an array length of 3 (elements at index 0,1,2) then with your code you get a value of 0,1,2 or 3. Since 3 is higher than the highest index value (2) you get the out of range error.
Solution: Use spawnPoints.Length - 1 for the max value.