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

时间:2018-05-16 21:01:01

标签: c# unity3d

我在第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;
            }
        }
    }
}

这就是我得到的错误:

  

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

1 个答案:

答案 0 :(得分:9)

你有一个额外的开场括号:

  if (level <= Application.levelCount - 1) { //here
  { //also here
在IsLevelUnlocked()