统一成员修饰语公共必须先于

我已经解决了这个问题,但是当事情变得更加疯狂时,我意识到尝试实现这个目标是多么愚蠢,因为它最终显然没有任何好处。

如果你有类似的问题,请随意查看这个问题,也许你会学到一两件事。 Idk¯\ _(ツ)_ /¯

人们在我这个网站上问过这个问题,但是这些都不是同一个问题。 我确定在检查代码时我可能错过了一些东西,但我无法弄清楚它是什么。 现在Unity正在困扰我,据说我不会把公共修饰符放在正确的位置,即使它正是应该的位置,从我所看到的。

让我快点告诉你……


Unity返回给我的错误:

Assets\saveFiles.cs(15,1): error CS1585: Member modifier 'public' must precede the member type and name 

我的代码 (我在这里发布这个很长的块有点疯狂,只是忽略那些我很难删除的评论。这就是我进一步开发的时候。)

 using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.EventSystems; using System.IO; using System.Windows.Forms; using System.Runtime.InteropServices; using System.Drawing; using System.Security.Permissions; // Allows permission requests from within script. VERY IMPORTANT. using System.Security.AccessControl; // Also as important for the same reason. [ComVisibleAttribute(true)] public sealed class FileIOPermission{}(AllAccess View, string MyDocuments) // Grants access to the User's Documents folder. public class saveFiles : MonoBehaviour { [DllImport("System.Windows.Forms.dll")] private static extern void SystemWindows(); [DllImport("System.Drawing.dll")] private static extern void SystemDrawing(); public string MyDocuments = System.Environment.GetFolderPath( (System.Environment.SpecialFolder.MyDocuments) ); // Reserve these variables for save file memory. public string UserData; public string UserConfig; public bool IsUserAvailable; void Start () { // On game execution, check for the game's configuration files. Load if they exist, save blank ones if they don't. // (Don't save in the Steam client's user data directory until you are aware of a way to find which user is logged into Steam.) // Check for saved progress and load it into memory if available. If not, it creates one and prepares it for editing. if(System.IO.File.Exists(System.Environment.GetFolderPath( (System.Environment.SpecialFolder.MyDocuments) ) + "/SaveData/tanky bois/" + "user.sav") == true) { UserData = System.IO.File.ReadAllText(System.Environment.GetFolderPath( (System.Environment.SpecialFolder.MyDocuments) ) + "/SaveData/tanky bois/" + "user.sav"); } else { System.IO.File.Create(System.Environment.GetFolderPath( (System.Environment.SpecialFolder.MyDocuments) ) + "/SaveData/tanky bois/" + "user.sav"); UserData = "statsA{\"xp\" : 0, \"money\" : 2000, \"MatchInProgress\" : false} Inventory{\"Default\":1;} loadout{1 null null null null}"; System.IO.File.WriteAllText(System.Environment.GetFolderPath( (System.Environment.SpecialFolder.MyDocuments) ) + "/SaveData/tanky bois/" + "user.sav", UserData); // Rules for UserData string: // Inventory is stored as: "[ItemTag string]:[QuantityOfItem integer];" // // Optionally, you can add extra info about the item from within a parentheses, placed after [ItemTag]. Useful for upgrades and equipment, leveling up, etc. // (eg "Default( [JSON METADATA] ):1;") // // Anything in quotes is a string, otherwise it is an integer or a boolean value depending on the returned value. // (eg 24 as an integer, true/false/null as a boolean) // // Loadout section is stored as 5 different inventory slot numbers, seperated by spaces. // Each number represents which item listing, counting from the start to the end of the Inventory string. // (eg "Inventory{weaponA:1;weaponB:1;weaponC:1;weaponD:1;} loadout{1 3 4 null null}" // will return WeaponA in slot 1, weaponC in slot 2, weaponD in slot 3, and slots 4 and 5 empty) // // Majority of user save data will use JSON format or one of a similar syntax. // (This applies to pretty much 100% of the settings file.) } // Check for user settings and load it into memory if available. If not, it creates one and prepares it for editing. if(System.IO.File.Exists(System.Environment.GetFolderPath( (System.Environment.SpecialFolder.MyDocuments) ) + "/SaveData/tanky bois/" + "cfg") == true){ UserConfig = System.IO.File.ReadAllText(System.Environment.GetFolderPath( (System.Environment.SpecialFolder.MyDocuments) ) + "/SaveData/tanky bois/" + "cfg"); } else { System.IO.File.Create(System.Environment.GetFolderPath( (System.Environment.SpecialFolder.MyDocuments) ) + "/SaveData/tanky bois/" + "cfg"); }; } public void saveUsr() { // Code for Windows Standalone: System.IO.File.WriteAllText(System.Environment.GetFolderPath( (System.Environment.SpecialFolder.MyDocuments) ) + "/SaveData/tanky bois/" + "user.sav", UserData); System.IO.File.WriteAllText(System.Environment.GetFolderPath( (System.Environment.SpecialFolder.MyDocuments) ) + "/SaveData/tanky bois/" + "cfg", UserConfig); } } 

那么在这种情况下,为什么Unity开始疯狂地要求我添加一个“公共”修饰符,哪里已经存在?

如果我错过了什么,请告诉我。

谢谢。

让我们重新格式化您的代码以便于阅读:

 .... [ComVisibleAttribute(true)] public sealed class FileIOPermission { } (AllAccess View, string MyDocuments) // Grants access to the User's Documents folder. public class saveFiles : MonoBehaviour { .... 

你现在能看到问题吗?

(AllAccess View, string MyDocuments)不在任何类中,因此编译器试图找出这意味着什么,并且它认为您正在尝试声明类或接口或枚举,并且最好的猜测是你是缺少修饰语。

它看起来像你从其他地方错误地复制并粘贴了这一行。 你应该删除它。