# Spawn point movement problem

Hi.
I have problem with my spawn point movement. It should be moving in right direction and spawn “stones”. The problem is with spawning, spawn point is moving on X-axis, but it still spawning at the same first position. How to fix it? Please help.

``````    public GameObject Stone;
float randX;
Vector2 whereTospawn;
public float spawnRate = 2f;
float nextSpawn = 1.0f;
//spawn movement
public float speed = 5f;
// Use this for initialization
void Start () {

}

// Update is called once per frame
void Update () {
transform.Translate(Vector2.right * Time.deltaTime * speed);

if (Time.time > nextSpawn)
{
nextSpawn = Time.time + spawnRate;
randX = Random.Range(20f, 20f);
whereTospawn = new Vector2(randX, transform.position.y);
Instantiate(Stone, whereTospawn, Quaternion.identity);
}
}
``````

you already set up whereTospawn, remove new from whereTospawn = new.

``````     public GameObject Stone;
float randX;
Vector2 whereTospawn;
public float spawnRate = 2f;
float nextSpawn = 1.0f;
//spawn movement
public float speed = 5f;
// Use this for initialization
void Start () {

}

// Update is called once per frame
void Update () {
transform.Translate(Vector2.right * Time.deltaTime * speed);

if (Time.time > nextSpawn)
{
nextSpawn = Time.time + spawnRate;
randX = Random.Range(20f, 20f);
whereTospawn = Vector2(randX, transform.position.y);
Instantiate(Stone, whereTospawn, Quaternion.identity);
}
}
``````

I solve my problem by increasing vector2.
Now it is working, not exactly as i want from beginning, but similarly.

``````  public GameObject Stone;
float randX;
Vector2 whereTospawn,vec;
public float spawnRate = 2f;
float nextSpawn = 1.0f;
public float a = 10f, b = 10f;
//spawn movement
public float speed = 5f;
// Use this for initialization
void Start () {

}

// Update is called once per frame
void Update () {
transform.Translate(Vector2.right * Time.deltaTime * speed);

if (Time.time > nextSpawn)
{
nextSpawn = Time.time + spawnRate;
randX = Random.Range(a, b);
vec = new Vector2(randX, transform.position.y);
whereTospawn = vec;
a += 20;
b += 20;
Instantiate(Stone, whereTospawn, Quaternion.identity);
}
}
``````