"Unexpected symbol `else'" 如何解决此问题(if语句后没有分号)?



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

这是我得到的错误:

资产/脚本/播放器首选项管理器.cs(56,30(:错误 CS1525:意外 符号"其他">

你有一个额外的左括号:

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

in IsLevelUnlocked((

最新更新