I HAVE FOUND THE PROBLEM, I SHOULD NEVER HAD MADE THOSE PREFABS BECAUSE THEY DON"T UPDATE ON RUN, SO I ASSIGNED THE SPAWNS TO THE GAMEOBJECT IN THE HIERARCHY INSTEAD
Hello fellow ForumMembers,
I found a way to Instantiate my Obstacles to an empty gameobject.
The next problem I encounter is that when I try to move the empty gameobject ,where it suppose to be spawned. It doesn’t update its position.
Also it seems like that the objects keep spawning at that same position even when I move the gameobjects to another position before pressing on start.
This is the script I made
var Spawn1 : GameObject;
var Spawn2 : GameObject;
var Spawn3 : GameObject;
var Spawn4 : GameObject;
var Spawn5 : GameObject;
//The Obstacle
var Obstacles : GameObject;
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, Spawn1.transform.position, Quaternion.identity);
}
if(Spawn == 1){
Debug.Log("spawn1");
Instantiate(Obstacles, Spawn2.transform.position, Quaternion.identity);
}
if(Spawn == 2){
Debug.Log("spawn2");
Instantiate(Obstacles, Spawn3.transform.position, Quaternion.identity);
}
if(Spawn == 3){
Debug.Log("spawn3");
Instantiate(Obstacles, Spawn4.transform.position, Quaternion.identity);
}
if(Spawn == 4){
Debug.Log("spawn4");
Instantiate(Obstacles, Spawn5.transform.position, Quaternion.identity);
}
}
}
InvokeRepeating let me call the function each second.
var Spawn 1: GameObject; is an empty Object were the Obstacles should be Instantiate.
Random.Range let me to randomize the position of the Obstacle each time the function has been called.
here have a picture.
thx for reading.
