错误(86,9):BCE0044:期待EOF,找到' case'

时间:2016-09-08 02:23:53

标签: unity3d compiler-errors unityscript

我收到了这个错误:

  

(86,9):BCE0044:期待EOF,找到' case'。

我一直得到同样的错误。我想做的是回到上一个场景。这个脚本适用于我将在场景中使用的按钮。这是我的剧本:

{

#pragma strict

import UnityEngine.SceneManagement;

@script AddComponentMenu ("EGUI/UI_Elements/Button")

// public class EGUI_Button extends EGUI_Element {}

// List of built-in functionality types
public enum ButtonAction
{
    None,                   // Do nothing
    Custom,                 // Call function (name in callFunction) with parameter for actionRecipient object (this gameObject is default)
    LoadLevel,              // Load level with index/name in parameter
    RestartLevel,           // Restart current level
    ExitGame,               // Close application
    SetQuality,             // Set quality level according to parameter (Fastest, Fast, ... Fantastic)
    DecQuality,             // Decrease quality level 
    IncQuality,             // Increase quality level  
    SetResolution,          // Set screen resolution according to parameter (1024x768, 1920x1080 ... etc)
    OpenURL,                // Open URL specified in parameter
    CloseEverything,        // Close/disable whole GUI manager and all related GUI-elements. 
    Resume,                 // Close parent GUI-element and set time-scale to 1
    ShowAnother,            // Show GUI-element specified in actionRecipient
    ShowPrevious,           // Show previous GUI-element
    HideThis,               // Hide parent GUI-element  
    HideThis_ShowAnother,   // Hide parent GUI-element and show window specified in actionRecipient
    HideThis_ShowPrevious,  // Hide parent GUI-element and show previous window
    SoundSwitch,            // Enable/Disable all sounds in the scene
    LoadPreviousLevel,      // Load the previous level if there is one else load load the current one
};

var onClickAction: ButtonAction;    // Action preset to perform onClick
var actionRecipient: GameObject;    // Optional link to action recipient object
var callFunction: String;           // Optional name of custom function to call
var parameter: String;              // Optional parameter to send/use in the Action

//=====================================================================================================
// Overload parent OnClick function to Perform built-in actions
function OnClick () 
{
    //     super.OnClick();
    PerformAction ();
}

//----------------------------------------------------------------------------------------------------
// Perform built-in actions according to selected type (onClickAction)
function PerformAction () 
{
    switch (onClickAction)
    {
        case ButtonAction.None:
            break;

        case ButtonAction.Custom:
            if(!actionRecipient)
                actionRecipient = gameObject;
            if(parameter.Length > 0)
                actionRecipient.SendMessage (callFunction, parameter, SendMessageOptions.DontRequireReceiver);
            else
                actionRecipient.SendMessage (callFunction, SendMessageOptions.DontRequireReceiver);
            break;

        case ButtonAction.LoadLevel:
            Time.timeScale = 1;
            try
                SceneManager.LoadScene(int.Parse(parameter));
            catch(error)
                SceneManager.LoadScene(parameter);
            break;

        case ButtonAction.RestartLevel: 
            Time.timeScale = 1;
            SceneManager.LoadScene(SceneManager.GetActiveScene().name);
            break;

        case ButtonAction.LoadPreviousLevel: 
            Time.timeScale = 1;
            if (SceneManager.GetActiveScene().buildIndex > 0) // if not the first scene load the prvious scene
                SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex - 1);
            else
                SceneManager.LoadScene(0);
            break;
    }
}
        case ButtonAction.ExitGame: 
            Application.Quit();
            break; 

        case ButtonAction.SetQuality: 
            switch (parameter)
            {
                case "Fastest":
                QualitySettings.SetQualityLevel(QualityLevel.Fastest);
                break;

                case "Fast":
                QualitySettings.SetQualityLevel(QualityLevel.Fast);
                break;

                case "Simple":
                QualitySettings.SetQualityLevel(QualityLevel.Simple);
                break;

                case "Good":
                QualitySettings.SetQualityLevel(QualityLevel.Good);
                break;


                case "Beautiful":
                QualitySettings.SetQualityLevel(QualityLevel.Beautiful);
                break;


                case "Fantastic":
                QualitySettings.SetQualityLevel(QualityLevel.Fantastic);
                break;
            }
            break;  

        case ButtonAction.IncQuality: 
            QualitySettings.IncreaseLevel();
            break; 

        case ButtonAction.DecQuality: 
            QualitySettings.DecreaseLevel();
            break; 

        case ButtonAction.SetResolution: 
            Screen.SetResolution ( int.Parse(parameter.Substring(0,parameter.IndexOf("x"))),  int.Parse(parameter.Substring(parameter.IndexOf("x")+1)), Screen.fullScreen);
            break;

        case ButtonAction.OpenURL: 
            Application.OpenURL(parameter);
            break;               

        case ButtonAction.CloseEverything: 
            GetGUIManager().gameObject.SetActive(false);
            break;                                                                                                                                                                                                                                                                      

        case ButtonAction.Resume: 
            Time.timeScale = 1;
            transform.parent.gameObject.SendMessage("Disable");
            break; 

        case ButtonAction.ShowAnother:
            if(actionRecipient)
                actionRecipient.GetComponent(EGUI_Element).SetActivation(true, transform.parent.gameObject);
            break; 

        case ButtonAction.ShowPrevious:
            if(senderObject)
                senderObject.SetActive(true);
            break; 

        case ButtonAction.HideThis:
            transform.parent.gameObject.SendMessage("Disable");
            break; 

        case ButtonAction.HideThis_ShowAnother:
            if(actionRecipient)
                actionRecipient.GetComponent(EGUI_Element).SetActivation(true, transform.parent.gameObject);
            transform.parent.gameObject.SendMessage("Disable");
            break; 

        case ButtonAction.HideThis_ShowPrevious:
            if(senderObject)
                senderObject.SetActive(true);
            transform.parent.gameObject.SendMessage("Disable");
            break; 

        case ButtonAction.SoundSwitch:
            if(actionRecipient)
                actionRecipient.GetComponent(AudioListener).enabled = !actionRecipient.GetComponent(AudioListener).enabled;
            break; 
    }
}


}

3 个答案:

答案 0 :(得分:0)

您的switch-case,没有switch声明,您的某些cases不属于任何开关,如ButtonAction.SetQuality:ButtonAction.ExitGame

答案 1 :(得分:0)

case关键字必须位于switch块内。注意你的括号。

答案 2 :(得分:0)

此处,您的两个交换机案例之间:

                 SceneManager.LoadScene(0);
             break;
    }
}
            case ButtonAction.ExitGame:

您刚关闭了switch声明。去掉那里的牙箍,它应该没问题。