- Home /
Question by
Lord_amateur · Jul 01, 2018 at 10:42 AM ·
instantiatetagprefab-instance
Instantiate an object correctly
I have written the script for instantiating an object as:
IEnumerator SpwanCubes()
{
while (true)
{
cube=Instantiate (cube, position, rotation) as GameObject;
cube.tag = id;
yield return new WaitForSeconds (spawnrate);
}
}
But This happens when the objects are instantiated
Can somebody tell me a correct way to instantiate this object in such a way that I can assign a unique tag to the instantiated objects?
capture.jpg
(14.6 kB)
Comment
Best Answer
Answer by WinterboltGames · Jul 01, 2018 at 10:46 AM
Because you are instantiating the clone not the original prefab, try this...
IEnumerator SpawnCubes()
{
while (true)
{
var cubeClone = Instantiate(cube, position, rotation);
cubeClone.tag = id;
yield return WaitForSeconds(spawnRate);
}
}