deactivate and activate an object in a list

Viewed 30

I am a beginner. I want to create a game where there are six different positions and objects that spawn from them everytime player collides one of them and then they respawn. it s a loop until game finish. I am having a problem with positions; if player stays at a position it just collides continually. I need to deactivate the position that player collides and reactivate when player collides other position. Position were made with empthy object and its collider. I dont know where to add what. Thanks for your help

public class NewSpawnScript : MonoBehaviour{
public GameObject[] SpawnPoints;
public float spawnTime;
public GameObject[] threeD;
public List<GameObject> possibleSpawn = new List<GameObject>();
public List<GameObject> possibleThreeD = new List<GameObject>();

void Start()
{
    //to avoid spawn more then one object at a position
    for(int i=0;i<SpawnPoints.Length;i++)
    {
        possibleSpawn.Add(SpawnPoints[i]);
    }
    // to avoid to spawn same objects at different positions
    for (int l=0;l<threeD.Length;l++)
    {
        possibleThreeD.Add(threeD[l]);
    }
    InvokeRepeating("SpawnItems", spawnTime, spawnTime);
}
private void OnTriggerEnter(Collider other)
{
  
    if (other.gameObject.tag=="Obj")
    {
        //to avoid spawn more then one object at a position
        for (int i = 0; i < SpawnPoints.Length; i++)
        {
            possibleSpawn.Add(SpawnPoints[i]);
        }

        // to avoid to spawn same objects at different positions
        for (int l = 0; l<threeD.Length; l++)
        {
            possibleThreeD.Add(threeD[l]);
        }

        InvokeRepeating("SpawnItems", 2.5f, 2.5f);
    }

}

void Update()
{
    
}
void SpawnItems()
{
    if(possibleSpawn.Count>0 && possibleThreeD.Count>0)
    {
        for(int i=0;i<12;i++)
        {
            int spawnIndex = Random.Range(0, possibleSpawn.Count);
            int spawnObject = Random.Range(0, possibleThreeD.Count);
            GameObject newObj = Instantiate(possibleThreeD[spawnObject], possibleSpawn[spawnIndex].transform.position, possibleSpawn[spawnIndex].transform.rotation) as GameObject;

            newObj.GetComponent<Destroyer>().mySpawnPoint = possibleSpawn[spawnIndex];
            newObj.transform.parent = newObj.GetComponent<Destroyer>().mySpawnPoint.transform;

            possibleSpawn.RemoveAt(spawnIndex);
            possibleThreeD.RemoveAt(spawnObject);
            i++;
        }       
    }
}

}

0 Answers
Related