Hi, this is my first project in Unity and I’m making a simple 3D platformer. (I’m on a course where we learn the basics of making 3D and 2D games in Unity) Every time you finish/fail a level, you see a screen that says “Level Completed!”, “Continue” or “Level Failed!”, “Restart”. I’m trying to give the player the option to give up but I can’t get it working. We were given the following script:
void OnGUI() {
GUI.skin.label.fontSize = 20;
GUI.skin.label.alignment = TextAnchor.MiddleLeft;
if (levelComplete) {
if (LevelEndMessage("Level completed!", "Continue"))
{
int nextLevel = Application.loadedLevel + 1;
if (nextLevel >= Application.levelCount) nextLevel = 0;
Application.LoadLevel(nextLevel);
}
}
else if (levelFailed) {
if (LevelEndMessage("You tried.", "Keep trying"))
Application.LoadLevel(Application.loadedLevel);
if (GUI.Button(new Rect(Screen.width/2 - 200/2, Screen.height/2 + 100, 200, 50) "Give up")) Application.LoadLevel(0);
}
else {
GUI.skin.label.alignment = TextAnchor.MiddleLeft;
GUI.Label(new Rect(10, 10, 200, 30), "Time:" + (Time.time - startTime).ToString("#"));
GUI.Label(new Rect(10, 40, 200, 30), "Collected:" + collected + "/" + numTreasures);
}
}
and I can’t get it working. If I switch the
else if (levelFailed) {
if (LevelEndMessage("You tried.", "Keep trying"))
Application.LoadLevel(Application.loadedLevel);
if (GUI.Button(new Rect(Screen.width/2 - 200/2, Screen.height/2 + 100, 200, 50) "Give up")) Application.LoadLevel(0);
for
else if (player == null) {
//changed that ^
if (LevelEndMessage("You tried.", "Keep trying"))
Application.LoadLevel(Application.loadedLevel);
//if (GUI.Button(new Rect(Screen.width/2 - 200/2, Screen.height/2 //+ 100, 200, 50) "Give up")) Application.LoadLevel(0);
//remove that ^
I can play the game and restart after death, but I can’t give up. I’m a beginner (at best) at coding so I don’t know if this is enough information for troubleshooting. The game won’t run and it gives the following errors for the line that I removed: “A new expression requires () or after type” and “Internal compiler error during parsing, Run with -v for details”.
Thank you and sorry if this is a common rookie mistake that I should be able to fix on my own.