Hi,
I’m trying tom make a script where some objects spawn after previous objects collided with my main character and changed tags. I wrote 5 different scripts, all of them had bugs cause of “yield” or “destroy” statements, so i came up with this:
function Spawn()
{
//Position 1
var obj1 : GameObject = carPrefabs[Random.Range(0, carPrefabs.length)];
var pos1: Transform = spawnPoint1;
var Obj1 : GameObject = Instantiate(obj1, pos1.position, pos1.rotation );
Obj1.tag = "car";
//I know my problem is in this line, cause when the first object is spawned, it doesn’t have that tag, so it’s false
if(Obj1.tag == "carA"){
//Position 2
var obj2 : GameObject = carPrefabs[Random.Range(0, carPrefabs.length)];
var pos2: Transform = spawnPoint2;
var Obj2 : GameObject = Instantiate(obj2, pos2.position, pos2.rotation );
Obj2.tag = "car";
if(Obj2.tag == "carA"){
//Position 3
// And so on...
}
}
I’m trying to avoid yield cause of my previous bugs, but i don’t know if it’s possible to do this in some other way.
I could really use an advise,
Thanks!