I have spawn points around my scene and I’m looking to spawn a prefab from a randomly selected one, I have each of my spawn points tagged and reference it in the code, I’m trying to piece it together with another question I’m following but having no luck, this is what I have below:
using UnityEngine;
using System.Collections;
public class spawn : MonoBehaviour
{
// Prefab to spawn
public GameObject disc;
//The time (in seconds) in which the new prefab will be destroyed
public int destroyTime = 15;
//The time it takes for the prefab to be spawned
public float spawnTime = 5;
//Keeps track of the current spawn time
private float curSpawnTime = 5;
Vector3[] spawnPoints;
int endOfArray;
void Start()
{
GameObject objs = GameObject.FindGameObjectsWithTag("SpawnPoints");
foreach(GameObject obj in objs)
{
spawnPoints = objs.GetComponent<Transform>().position;
}
endOfArray = spawnPoints.Length;
InvokeRepeating ("Spawn", 0.01f, 10.0f);
}
void Spawn()
{
Instantiate(disc,spawnPoints[Random.Range(0,endOfArray)],Quaternion.identity);
}
}
But this is the error I’m getting: