3
To create the floor, I did it this way:
I created a gameobject and then assigned an Sprite render, box Colider, rigidbody 2d and a script.
I created a Prefab and dragged the gameobject that I set up above to the Prefab and ready, so I created my floor and the Prefab that will be added to the game as the player advances.
I’ve also created 2 other objects, one to add a new Prefab (which is my floor) and one to destroy it when you step outside the camera boundary as the player advances.
In the script you assign to Prefab I check if there is a collision with one of the 2 objects above and 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 a type of floor, but I have other 3 types of floor/ Prefab with Polygon Collider in place of the box Collider (for having a different shape).
How do I make the new floor to be added a 4 prefabs Random that I have?
To better understand what I wrote above, see the image (any resemblance to the super mario is just copying):
Please avoid long discussions in the comments; your talk was moved to the chat
– Maniero