Your question can be understood in two ways. Leoverload gave the answer to the repeating position.
In case you do not want to repeat the same type of object (so all objects are unique), then do the following:
- Turn objSpawn into a
List<GameObject>
variable and in the start() function, add all instances from the array that's returned from FindGameObjectsWithTag
to it.
- Turn
objSpawn.Length
into objSpawn.Count
(which does the same but for lists)
In that same function add: objSpawn.Remove(objActual)
at the end.
If those objects are destroyed at some point and you want to create new instances of destroyed objects, ensure that in their Destroy event, you Add(gameObject)
to the list again.
Am giving you instructions instead of just code so you can learn to do this yourself in the future.
Also I have the feeling you need to learn how argumentsparameters work. Then you can ommit that objActual variable and instead pass the object to createObj(GameObject theObj)
directly.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…