jeudi 21 novembre 2019

How to spawn random 2D platforms that do not overlap in Unity?

I'm looking for a way to randomly spawn platforms that do not overlap with each other. All the tutorials I found on this topic are for an endless runner game type, and my project is not like that. So far I know how to spawn my platforms but I need those gaps between them. I'm a total begginer in Unity and C# so I'm looking for a simple code if possible.

My code now:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GameStateManager : MonoBehaviour {
public GameObject YellowPrefab;
    public int howManyYellow;

 void Start()
    { GameObject tmpYellow;

        for (int i = 0; i < howManyYellow; i++)
        {
            tmpYellow = Instantiate(YellowPrefab, new
                        Vector3(Random.Range(-50, 50), Random.Range(-
                        40, -17), 0), Quaternion.identity);
        }
  }

My platforms have box colliders used by platform effector, if that information is needed.




Aucun commentaire:

Enregistrer un commentaire