Hi,this is my first post on it.
I’m studying for develop game in unity with my team.
we have a problem with the project of the game:
the choices are two: static game or dynamic game.
Whe have choose static game: the player position is fixed,background flowing endlessly but the obstacles?
I thought of them generate from the right and scroll left until come out of the scene, and a destroyer destroys them.
following the tutorial mike Gaig, I inserted a quad which creates obstacles and make this script :
public class SpawnScript : MonoBehaviour {
public GameObject[] obj;
public float spawnMin = 1f;
public float spawnMax = 3f;
public Vector3 pos = new Vector3(26.10f,-0.07f,0);
public float speed = 2.0f;
void Start () {
StartCoroutine(Spawn());
}
IEnumerator Spawn() {
while (true) {
GameObject clone;
clone = Instantiate (obj [Random.Range (0, obj.Length)], pos, Quaternion.identity) as GameObject;
//clone.transform.position += Vector3.left * Time.deltaTime * speed;
yield return new WaitForSeconds(Random.Range (spawnMin, spawnMax));
}
}
}
the script is, however, incomplete. I need to create obstacles and make them move to the left independently of one another, but I have no idea how to do.
Can you help me?
Sorry for my bad english. Thank you so much!
EDIT: I MADE THIS:
IEnumerator Spostamento(GameObject clone){
for(int i=0;i<300;i++){
clone.transform.position += Vector3.left * Time.deltaTime * speed;
yield return new WaitForSeconds (0.01f);
}
}
IEnumerator Spawn() {
while (true) {
GameObject clone;
clone = Instantiate (obj [Random.Range (0, obj.Length)], pos, Quaternion.identity) as GameObject;
StartCoroutine(Spostamento (clone));
yield return new WaitForSeconds(Random.Range (spawnMin, spawnMax));
}