With this Script I made,I can Instantiate the Objects. The only problem is that it haven’t been given a proper spawn location yet. I got some Empty gameobjects in the scene (the spawn location). My plan was when the Random.range(0,4)chose a number between 0 and 4 It would instantiate the object.This all works fine but as I mentioned I can’t give it a proper spawn location
don’t look at the if(GameObject.Find(“Player”).GetComponent(Rigidbody2D).isKinematic == false){ This was nessecary so that it wouldn’t instantiate right from the start
//Several SpawnPoints
var Spawn1 : GameObject;
var Spawn2 : GameObject;
var Spawn3 : GameObject;
var Spawn4 : GameObject;
var Spawn5 : GameObject;
//The Obstacle
var Obstacles : GameObject;
//Repeats the function every second
InvokeRepeating("Start2", 0, 1.0);
function Start2()
{
if(GameObject.Find("Player").GetComponent(Rigidbody2D).isKinematic == false){
var Spawn = Random.Range(0,4);
if(Spawn == 0){
Debug.Log("spawn0");
Instantiate(Obstacles);
}
if(Spawn == 1){
Debug.Log("spawn1");
Instantiate(Obstacles);
}
if(Spawn == 2){
Debug.Log("spawn2");
Instantiate(Obstacles);
}
if(Spawn == 3){
Debug.Log("spawn3");
Instantiate(Obstacles);
}
if(Spawn == 4){
Debug.Log("spawn4");
Instantiate(Obstacles);
}
}
}
Thanks for reading, I hope you can help me out.