- Home /
Question by
ryanconway · Feb 14, 2014 at 12:29 AM ·
instantiateprefablevelscrollinfinite
Scrolling level Instantiate after cycle
When I run my level in generates 10 obstacles, similar to Mario pipes. these then scroll across the level and finish about position.x 9000, I need my script to generate some more at that point and destroy the previous ones, to make the level infinite .
at the minute obstacle is a prefab and X is the amount of pipes to spawn at start.
using UnityEngine;
using System.Collections;
public class levelgeneration : MonoBehaviour {
public GameObject obstacle;
public float x = 1;
public float moveSpeed = 0.03f;
void Update () {
transform.position += new Vector3(5, 0, 0);
float y = Random.Range(-27.1157f, -18.05732f);
if(x < 15) {
Instantiate(obstacle, new Vector3(x * 12.0f, y, 0),Quaternion.identity);
x++;
}
if (transform.position.x > 9000) {
}
}
}
Comment
What is this script attached to - are you wanting to track THIS script's pos, or the things you are instantiating?
This script is attached to a prefab
[1]: /storage/temp/22173-numjg84[1].png
numjg84[1].png
(394.9 kB)