I have a script here that spawns X amount of objects when called upon. The code is written with Transform, not Vector3 and spawns the object randomly in an array of transform points. I am trying to prevent spawn overlapping. I understand the function .CheckSphere, however that is for Vector3s and will not work in this instance. What is the equivalent to this but applicable to Transforms? Thanks for any help.
public class RandomMoneySpawner : MonoBehaviour
{
public GameObject objectToSpawn;
public Transform[] spawnPoints;
public int amountToSpawn;
private int amountSpawned;
public float spawnCollisionCheckRadius;
void Start()
{
amountSpawned = 0;
}
// Update is called once per frame
void Update()
{
if(amountSpawned < amountToSpawn)
{
SpawnObject();
}
}
public void SpawnObject()
{
Transform _sp = spawnPoints[Random.Range(0, spawnPoints.Length)];
Instantiate(objectToSpawn, _sp.position, _sp.rotation);
amountSpawned ++;
}
public void ResetSpawnCount()
{
amountSpawned = 0;
}
}