Instantiating a row of spheres

using UnityEngine;
using System.Collections;

public class PreviousPosition : MonoBehaviour {
	public Vector3 curpos;
	public Vector3 temp = new Vector3(0,0,2f);
	public GameObject bomb;


	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
		curpos = transform.position + temp;
		Instantiate (bomb, curpos, transform.rotation);
		
	
	}
}

This was the code.

And this is what happened.

Why are there so many speheres?
I thought this code would spawn one sphere at 2 points further on Z axis. Instead it instantiates tons of spheres at each spheres place.

Thanks.

Update runs every frame so you are instantiating a sphere every time and it is moving along the screen as you are also updating the position of the corpus.
If you want to instantiate just one at the beginning - move:
curpos = transform.position + temp;
Instantiate (bomb, curpos, transform.rotation);
to the Start() function
hope that helps,

Ehm. That’s because Update () ist called on every frame? :slight_smile:
See Unity - Manual: Order of execution for event functions