- Home /
Instantiating infinite platforms in a row problem
My problem is really simple: I have a prefab that I need to instantiate every second. Those platforms are in a row and are destroyed by a destroyer. The code is really simple (and surely stupid):
public class StartSpawnScrpt : MonoBehaviour {
public GameObject obj;
// Use this for initialization
void Start () {
Spawn();
}
void Spawn(){
Instantiate(obj, transform.position, Quaternion.identity);
Invoke("Spawn", 1);
}
}
This code is attached to a spawner that is attached to the moving main camera. The problem is that after the first spawn call, next are translated downwards and I really can't figure out why.
Answer by YoungDeveloper · Feb 13, 2014 at 10:40 PM
Try this
// Use this for initialization
void Start(){
StartCoroutine(Spawner());
}
IEnumerator Spawner(){
while(true){
Instantiate(obj, obj.transform.position, Quaternion.identity);
//or instead of Quaternion.identity use obj.transform.rotation
yield return new WaitForSeconds(1f);
}
}
No, nothing changed. The spawner is still translated downwards...
Then obj or spawner pivot isnt corrent, code it correct.
I don't think so, because the first spawn call is correct, than when Invoke() is called the translation happens
Your answer
![](https://koobas.hobune.stream/wayback/20220613133429im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
What's wrong with my script? 1 Answer
extra GameObjects Spawning 2 Answers
Spawning prefabs dependant upon Health UI? 2 Answers
2D 360 degress platformer example needed 0 Answers