In unity, I have an infinite platform generator that generates platforms while the character ascends in the Y axis , the problem is that there are times when platforms are generated On top of other platforms and they overlap, I would like to know how to make them separate if they collide when they are generated. I've written this in the platform prefabs script, but it does not work. I've put all the platforms with the tag "Floor" , or the tag "Enviroment" .
(I do not write the entire script well, but it's this)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NoBlocking : MonoBehaviour {
public static Transform trs;
// Use this for initialization
void Start () {
trs = GetComponent<Transform>();
}
// Update is called once per frame
void Update () {
}
void OnCollisionEnter2D(Collision2D col)
{
if (col.gameObject.tag == "Enviroment" || col.gameObject.tag == "Floor")
{
if (transform.position.x <= 0)
{
transform.position = new Vector3(transform.position.x + 4f, transform.position.y, transform.position.z);
Debug.Log(transform.position.x);
}
else
{
transform.position = new Vector3(transform.position.x - 4f, transform.position.y, transform.position.z);
}
Debug.Log("hola");
}
}
}