I am new to unity and I am making a menu, and I was wondering how would I make the background move, while the menu buttons move along with the main camera. So far I have made a script call BG_GENERATE and attached it to a 3d object (is this the right way to do this?).
Code:
using UnityEngine;
using System.Collections;
public class BG_Generator : MonoBehaviour {
public GameObject[] BGSlices;
public float y, spacing;
public int MaxTer;
protected float x;
void Start () {
x = transform.position.x + 5;
for (int i = 0; i < MaxTer; i++)
GenBG ();
}
void GenBG() {
Instantiate (BGSlices[Random.Range(0, BGSlices.Length)], new Vector3(x + spacing, y, 0), Quaternion.identity);
x += spacing;
}
void OnTriggerEnter2D (Collider2D other){
Debug.Log (other.tag);
Destroy (other.gameObject);
GenBG ();
}
}