overlapping of enemy

hi there, i have script that has 2 public array variables called spawnPoints and spawnObjects, i have 9 spawnPoints and 4 spawnObjects. These 4 spawnObjects are placed on 4 spawnPoints. Here what i am doing is whenever i press the mouse button i m changing the position of spawnObjects to other spawnPoints, its working fine but the spawnObjects are overlapping some times.

please can anyone rewrite this code

using UnityEngine;
 using System.Collections;
 
 public class Forward : MonoBehaviour
 {
         public GameObject[] spawnPoint;
         private GameObject spawn;
         public GameObject[] spawnObjects;
         private GameObject objectSpawn;
 
         void Update ()
         {
                 if (Input.GetMouseButtonDown (0)) {
                         
                         int a = Random.Range (0, spawnPoint.Length);
                         int b = Random.Range (0, spawnObjects.Length);
                         spawn = spawnPoint [a];
                         objectSpawn = spawnObjects **;**

objectSpawn.transform.position = spawn.transform.position;
}
}
}

To avoid duplicate random values, generate a random sequence between 0 and spawnPoints.Length (exclusive).

Use a shuffle algorithm such as Fisher Yates to generate your sequences:

for (int i = length - 1; i > 0; i--)
{
  int j = random.Next(i + 1);
  int temp = array*;*

array = array[j];
array[j] = temp;
}

A possibility to fix this problem is to take an array for currently available positions for spawining, say AllowedPositions.

So, when the game starts:

AllowedPositions = new int[] { 0,1,2,3,4,5,6,7,8 }

Now run:

int a = Random.Range (0, AllowedPositions.Length)

and pick ath element from AllowedPositions and remove it from the array.

int randomAvailablePosition = AllowedPositions[a];

e.g., Random.Range returns 3, then:

AllowedPositions = new int[] { 0,1,2,   4,5,6,7,8 }

Since 3 is not in the AllowedPositions array so you can not pick this position again and overlapping will not occur.

A better option is to use List<T> since manipulation would be easy.