Hey, I’m pretty new to unity and am making an infinite runner at the moment. I made it so that the platforms under the character move instead of the actual character.However, when I clone the platform, it doesn’t move, even though I have movement set up in it’s update function. The first 2 place holder platforms I added in do move, so I am really stumped.
Here is the platform spawner script:
public class EnviroHandler : MonoBehaviour {
public GameObject ground;
private float groundWidth;
private float interval;
private float intervalProgression = 0;
private ArrayList groundList = new ArrayList();
// Use this for initialization
void Start () {
groundWidth = ground.GetComponent<BoxCollider2D>().size.x;
interval = ground.GetComponent<groundMovement>().speed;
}
// Update is called once per frame
void Update () {
if(intervalProgression >= interval){
groundList.Add(Instantiate(ground, new Vector3(9.2f, -2, 0), Quaternion.identity));
intervalProgression = 0;
}else{
intervalProgression += Time.deltaTime;
}
}
}
and here is the script each platform comes with:
public class groundMovement : MonoBehaviour {
//declaration for certain attributes
public int speed = 3;
public float endPos;
public float width;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
// Move the object to the left, using speed vasriable
transform.Translate(Vector3.left * Time.deltaTime * speed);
//destroy object when it moves off screen, based on x position and width
if (transform.position.x >= endPos + width){
Debug.Log("destroyed");
Destroy(this);
}
}
}
Any help is greatly appreciated.