So, I finished the course on Block Breaker and I thought about adding in some little touches here and there. First, I wanted to add a button that would pop up at the bottom of the screen when the player finished breaking all the blocks. I got my coding to about here:
public class Level : MonoBehaviour
{
//parameters
[SerializeField] int breakableBlocks; //Serialized for Debugging purposes
[SerializeField] GameObject button;
[SerializeField] GameObject canvas;
I used this so I could drag my button prefab and already made canvas prefab into the Inspector. Then I edited the BlockDestroyed method
public void BlockDestroyed()
{
breakableBlocks--;
if(breakableBlocks <= 0)
{
GameObject nextButton = Instantiate(button) as GameObject;
nextButton.transform.SetParent(canvas.transform, false);
// sceneloader.LoadNextScene();
}
}
Doing this let me have a button appear at the bottom left of my screen saying āNext Levelā
However, the button is nonfunctional, even though Iāve set it to Sceneloader.LoadNextScene when clicked on.
Iām not sure how to Instantiate a button properly.
Another thing is that Iām not sure how to make the ball disappear after all the blocks are broken, which means that it falls into the Lose Collider when I try to select the button.
Sorry for how long this post got, but Iām really interested in understanding how to perform these functions.
Thank you in advanced!