Hello Unity community, i make this car spawn script. I have 2 problem about this script.
1- When i run game its normal working and spawn 6 car ( 3 Left side 3 right side) but when i trigger car spawner its spawn 12 car not 6 car. I cant fix it.
2- Sometimes cars spawn same spawn point how i can make it non repeating ?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
public class SpawnSystem : MonoBehaviour
{
public GameObject[] cars;
public Transform[] leftSpawnPoint;
public Transform[] rightSpawnPoint;
void Start()
{
for (int i = 0; i < 3; i++)
{
Instantiate(cars[Random.Range(0, cars.Length)], leftSpawnPoint[Random.Range(0, leftSpawnPoint.Length)].position, Quaternion.Euler(0, 180, 0));
Instantiate(cars[Random.Range(0, cars.Length)], rightSpawnPoint[Random.Range(0, rightSpawnPoint.Length)].position, Quaternion.identity);
}
}
public void SpawnCar()
{
for (int i = 0; i < 3; i++)
{
Instantiate(cars[Random.Range(0, cars.Length)], leftSpawnPoint[Random.Range(0, leftSpawnPoint.Length)].position, Quaternion.Euler(0, 180, 0));
Instantiate(cars[Random.Range(0, cars.Length)], rightSpawnPoint[Random.Range(0, rightSpawnPoint.Length)].position, Quaternion.identity);
}
}
}
