- Home /
How to make a circular 2D map.
Hi !
I'm learning Unity and I'm facing a problem. I want to create a 2D horizontal platform map scene, but a circular one. If the player reaches the end of the map, it will continue at the start of the scene, like a loop. Note: It's not an endless map, it's a circular map.
Is it possible ? How ?
Thank you.
Answer by itay3x3 · Jan 03, 2016 at 09:24 AM
Try this:
public GameObject map;
public GameObject player;
int loopNumber;
float endOfMap;
void Update() {
endOfMap = map.transform.position.x + map.transform.localScale.x / 2;
if (player.transform.position.x == endOfMap + loopNumber * map.transform.localScale.x) {
map = Instantiate(map, new Vector2(endOfMap + loopNumber * map.transform.localScale.x), Quaternion.identity) as GameObject;
loopNumber++;
}
}
Answer by mauleTTT · Jan 03, 2016 at 05:57 PM
Hi @itay3x3 !
Thanks for your response, I'm trying it now but it don't work ! The player position never gets the endofMap position, so the if is never done.
What do you instance in map GameObject variable ? Also, the new Vector2 is missing the y position, what do you put there ?
Thanks again !
Your answer
Follow this Question
Related Questions
How do I end my level? 2 Answers
Animation disturbing circular rotation 1 Answer
Glitchy collisions 0 Answers
Raycast on ui elements not working? 0 Answers
Moving in a circle around a parent 1 Answer