Quantcast
Channel: Questions in topic: "endless"
Viewing all articles
Browse latest Browse all 123

Generate new blocks to land on

$
0
0
Dear unity Community, I am trying to make a sort of endless runner, and I am trying to generate the next block when you touch the current block. So it will be endless. The distance has to be random but has to have a max so it is possible to make it and not to far away. It is in 2D. I wrote the following script, but with this the block only comes up on 1 place. The block taken is random but now I need the distance to be correct.. using UnityEngine; using System.Collections; public class createNewBlocks : MonoBehaviour { public Transform[] teleport; public GameObject[] prefeb; public float XPosition = 0.0f; public float YPosition = -2.6f; void OnCollisionEnter2D(Collision2D coll) { int tele_num = Random.Range(0,8); int prefeb_num = Random.Range(0,2); XPosition = XPosition += Random.Range (1, 20); Debug.Log ("Xposition =" + XPosition); Instantiate(prefeb[prefeb_num], teleport[tele_num].position = new Vector2(XPosition,YPosition), teleport[tele_num].rotation ); } } It would be great if someone could help me, thanks in advance! Kind Regards, Marijn

Viewing all articles
Browse latest Browse all 123

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>