- Home /
Current Level Load Again After Level Completion
I developed a jigsaw puzzle game and almost complete but there is one problem when I complete the level, the completion panel showing automatically which I set in C sharp script and I want this. But the problem is, it's not working when I restart that level again or trying to close the completion panel to start the level again. It works when I restart the game.
I assign the Level Complete script to all pieces of the puzzle, which is:
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class LevelComplete : MonoBehaviour { public static int remainingPieces = 4;
public GameObject Complete;
void Update()
{
if (remainingPieces == 0)
{
Complete.gameObject.SetActive(true);
}
}
}
Please help!
Do you reset the static variable remainingPieces to 4 again somewhere? and where do you decrease it?
Thank You for your reply! Here is Some screenshot of my main pieces script and Level Complete Script.
I assigned the Level Script to all pieces of the puzzle and then assigned the level complete panel to all pieces. It works but when I click the restart button in complete panel screen then it is not working and also click on the level button from the menu it's showing the complete panel screen.
I think there is need some coding to reset it again when I click on the restart button but I don't how to do that. Please guide me about this if you have any idea.
Answer by rh_galaxy · Sep 13, 2020 at 01:33 PM
I think you should not assign the LevelComplete-script to all 4 pieces, but instead assign it to an empty gameobject "PuzzleLevel" for example. Use right mouse button in the scene view and select "Create Empty". And when you reset the the puzzle, either you do LoadScene() again to get the objects to recreate and run the Start() function again, or you will have to keep track of your puzzle pieces and run a Reset() function on each of the pieces.