I’m trying to make a spawn script that would randomly choose one of three spawn points which are located at three game objects. This is the first set of code I tried.
var spawn : Transform[];
var game_cube : Rigidbody;
var cube_count = 0;
InvokeRepeating("LaunchProjectile", 2, 3);
function Update() {
if (cube_count>= 10) {
CancelInvoke();
}
}
function LaunchProjectile () {
var randomPick : int = Random.Range(0,2);
instance = Instantiate(game_cube, spawn[randomPick].position, transform.rotation);
instance.velocity = Vector3.zero;
cube_count = cube_count +1;
}
It has no errors but the prefab objects I made are not spawning at all. So I tried making a basic script that could make it at least functional.
var game_cube : Rigidbody;
var spawn : Transform[];
var cube_count = 0;
var respawn1 : GameObject;
var respawn2 : GameObject;
var respawn3 : GameObject;
InvokeRepeating("LaunchProjectile", 2, 3);
function Update() {
if (cube_count>= 10) {
CancelInvoke();
}
}
function LaunchProjectile () {
var randomPick : int = Random.Range(0,2);
if(randomPick : 0){
spawn : respawn1;
}
if(randomPick : 1){
spawn : respawn2;
}
if(randomPick : 2){
spawn : respawn3;
}
instance = Instantiate(game_cube, spawn.position, spawn.rotation);
instance.velocity = Vector3.zero;
cube_count = cube_count +1;
}
I assume you assigned 3 transforms to 'spawn' with the Inspector, as well as game_cube?
– DaveA