This is my first project on Unity so I am learning as I go. I am creating a 2d scroller game and I’m at the point where I need to spawn the enemys. I have three enemys named: car, semi and bike. I have the logic of when the enemy will spawn and what enemy it will be. (I just have it print to the console of what vehicle it will be and what lane it will be in)
function enemyFunction () : IEnumerator {
var lane: int = Random.Range(1,4);
var vehicleType: int = Random.Range(1,7);
switch (vehicleType){
case 1: //Semi
case 2:
switch (lane){
case 1:
Debug.Log("Semi, lane 1");
yield WaitForSeconds (3);
enemyFunction();
break;
case 2:
Debug.Log("Semi, lane 2");
yield WaitForSeconds (3);
enemyFunction();
break;
case 3:
Debug.Log("Semi, lane 3");
yield WaitForSeconds (3);
enemyFunction();
break;
}
break;
case 3: //bike
switch (lane){
case 1:
Debug.Log("Bike, lane 1");
yield WaitForSeconds (3);
enemyFunction();
break;
case 2:
Debug.Log("Bike, lane 2");
yield WaitForSeconds (3);
enemyFunction();
break;
case 3:
Debug.Log("Bike, lane 3");
yield WaitForSeconds (3);
enemyFunction();
break;
}
break;
case 4: //car
case 5:
case 6:
switch (lane){
case 1:
Debug.Log("Car, lane 1");
yield WaitForSeconds (3);
enemyFunction();
break;
case 2:
Debug.Log("Car, lane 2");
yield WaitForSeconds (3);
enemyFunction();
break;
case 3:
Debug.Log("Car, lane 3");
yield WaitForSeconds (3);
enemyFunction();
break;
}
break;
}
}
enemyFunction();
I have this written on a master script that is connected to an empty game object. Would I want to have the actual code of spawning in this script, or would I have something that would refer to another script that is attached to the actual vehicle that I am spawning. I am completely lost on how to do this.