"意外的符号`else'"如何修复此问题(if语句后没有分号)?

The*_*t22 -8 c# unity-game-engine

我在第56行收到错误...有人可以告诉我为什么吗?我没有在if语句的末尾添加任何分号,我也使用右括号放置......这里有什么问题?我将不胜感激,谢谢!

这是我的代码:

using UnityEngine;
using System.Collections;

public class PlayerPrefsManager : MonoBehaviour {

    const string MASTER_VOLUME_KEY = "master_volume";
    const string DIFFICULTY_KEY = "difficulty";
    const string LEVEL_KEY = "level_unlocked_";

    public static void SetMasterVolume(float volume)
    {
        if (volume > 0f && volume < 1f) {

            PlayerPrefs.SetFloat (MASTER_VOLUME_KEY, volume);

        } else {

            Debug.LogError ("Master volume out of range");

        }
    }

    public static float GetMasterVolume()
    {
        return PlayerPrefs.GetFloat (MASTER_VOLUME_KEY);
    }

    public static void UnlockLevel (int level)
    {
        if (level <= Application.levelCount - 1) {

            PlayerPrefs.SetInt(LEVEL_KEY + level.ToString(), 1); //Use 1 for true

        } else {
            Debug.LogError("Trying to unlock level that isn't in build settings");
        }
    }

    public static bool IsLevelUnlocked(int level)
    {
        int levelValue = PlayerPrefs.GetInt (LEVEL_KEY + level.ToString ());
        bool isLevelUnlocked = (levelValue == 1);

            if (level <= Application.levelCount - 1) {
            {

                return isLevelUnlocked;

            } else {
                Debug.LogError("Trying to unlock level that isn't in build settings");
                return false;
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我得到的错误:

Assets/Scripts/PlayerPrefsManager.cs(56,30):错误CS1525:意外的符号"else"

Dus*_*ton 9

你有一个额外的开放支架:

  if (level <= Application.levelCount - 1) { //here
  { //also here
Run Code Online (Sandbox Code Playgroud)

在IsLevelUnlocked()中