To create the floor, I did this:
I created a gameobject and then assigned a sprite render, box colider, rigidbody 2d, and a script.
I created a prefab and dragged the gameobject that I set up above the prefab and ready, so I created my floor and the prefab that will be added to the game as the player advances.
I also created 2 other objects, one to add a new prefab (which is my floor) and another to destroy it when I leave the camera border as the player advances.
In the script that assigns to the prefab I check if there is any collision with one of the 2 objects above and I remove or add a new prefab:
void OnTriggerEnter2D (Collider2D o)
if (o.tag == "CreateGround"){
Instantiate(Resources.Load("Prefabs/Ground"), new Vector3 (5.4f, -4.574f, 0), Quaternion.identity);
else if (o.tag == "DestroyGround")
Destroy(gameObject);
}
It works perfectly for one type of floor, however I have 3 other types of floor / prefab with polygon collider in place of box collider (for having a different shape).
How do I make the new floor to be added a random of the 4 prefabs I have?
To better understand what I wrote above, see the image (any resemblance to super mario is just copydence):