Unity 3D - 错误太多
本文关键字:太多 错误 3D Unity | 更新日期: 2023-09-27 18:33:24
两个脚本从外观上生成了这些错误,它们如下所示:
------------------------------- 游戏信息 - 下面列出的编码: -------------------------------
using UnityEngine;
使用系统集合;
公共类 游戏信息 : 单行为 {
void Awake(){
DontDestroyOnLoad (transform.gameObject);
}
public static string PlayerName{ get; set; }
public static int PlayerLevel{ get; set; }
public static BaseCharacterClass PlayerClass{ get; set; }
public static int Speed{ get; set; }
public static int Endurance{ get; set; }
public static int Strength{ get; set; }
public static int Health{ get; set; }
}
-------------------------------另一个脚本是保存信息:-------------------------------
using UnityEngine;
使用系统集合;
公共类保存信息 {
public static void SaveAllInformation(){
PlayerPrefs.SetInt("PLAYERLEVEL", GameInformation.PlayerLevel);
PlayerPrefs.SetString("PLAYERNAME", GameInformation.PlayerName);
PlayerPrefs.SetString("SPEED", GameInformation.Speed);
PlayerPrefs.SetString("ENDURANCE", GameInformation.Endurance);
PlayerPrefs.SetString("STRENGTH", GameInformation.Strength);
PlayerPrefs.SetString("HEALTH", GameInformation.Health);
}
}
-------------------------------错误:-------------------------------
资产/标准 资源/脚本/保存和加载/保存信息.cs(7,67(:错误 CS0117:
GameInformation' does not contain a definition for
玩家级别'资产/标准 资产/脚本/保存和加载/保存信息.cs(7,29(:错误 CS1502:最适合重载方法匹配 'UnityEngine.PlayerPrefs.SetInt(string, int(' 有一些无效的 参数
资产/标准 资产/脚本/保存和加载/保存信息.cs(7,29(:错误 CS1503:参数
#2' cannot convert
对象"表达式键入"int">资产/标准 资产/脚本/保存和加载/保存信息.cs(8,69(:错误 CS0117:
GameInformation' does not contain a definition for
玩家名称'资产/标准 资产/脚本/保存和加载/保存信息.cs(8,29(:错误 CS1503:要键入的对象表达式
#2' cannot convert
参数 "字符串">资产/标准 资产/脚本/保存和加载/保存信息.cs(9,64(:错误 CS0117:
GameInformation' does not contain a definition for
速度'资产/标准 资源/脚本/保存和加载/保存信息.cs(9,29(:错误 CS1502:最适合重载方法匹配 'UnityEngine.PlayerPrefs.SetString(string, string(' 有一些无效的 参数
资产/标准 资源/脚本/保存和加载/保存信息.cs(9,29(:错误 CS1503:要键入的对象表达式
#2' cannot convert
参数 "字符串">资产/标准 资产/脚本/保存和加载/保存信息.cs(10,68(:错误 CS0117:
GameInformation' does not contain a definition for
耐力资产/标准 资产/脚本/保存和加载/保存信息.cs(10,29(:错误 CS1502:最适合重载方法匹配 'UnityEngine.PlayerPrefs.SetString(string, string(' 有一些无效的 参数
资产/标准 资产/脚本/保存和加载/保存信息.cs(10,29(:错误 CS1503:要键入的对象表达式
#2' cannot convert
参数 "字符串">资产/标准 资产/脚本/保存和加载/保存信息.cs(11,67(:错误 CS0117:
GameInformation' does not contain a definition for
强度资产/标准 资产/脚本/保存和加载/保存信息.cs(11,29(:错误 CS1502:最适合重载方法匹配 'UnityEngine.PlayerPrefs.SetString(string, string(' 有一些无效的 参数
资产/标准 资产/脚本/保存和加载/保存信息.cs(11,29(:错误 CS1503:要键入
#2' cannot convert
对象的表达式的参数 "字符串">资产/标准 资产/脚本/保存和加载/保存信息.cs(12,65(:错误 CS0117:
GameInformation' does not contain a definition for
健康'资产/标准 资产/脚本/保存和加载/保存信息.cs(12,29(:错误 CS1502:最适合重载方法匹配 'UnityEngine.PlayerPrefs.SetString(string, string(' 有一些无效的 参数
资产/标准 资产/脚本/保存和加载/保存信息.cs(12,29(:错误 CS1503:要键入的对象表达式
#2' cannot convert
参数 "字符串">
-------------------------------
在回复时请记住,我对编码相当陌生。谢谢!
-------------------------------
在编程世界中,这些都是非常基本的错误,如果您理解它们而不是仅仅下载脚本并希望它们都插入在一起,您会发现进步要容易得多。 下面我描述了每个错误的原因,以帮助您入门:
GameInformation' does not contain a definition for
PlayerLevel'
// This one means you're talking about PlayerLevel
// in GameInformation, but GameInformation doesn't have PlayerLevel
The best overloaded method match for `UnityEngine.PlayerPrefs.SetInt(string, int)' has some invalid arguments
// This means that you're trying to call SetInt with something that isn't a string
// or something that isn't an int
Argument #2' cannot convert object' expression to type `int'
// Same as above, trying to give *object* to something that expects *int*
GameInformation' does not contain a definition for
PlayerName'
// GameInformation doesn't have PlayerName either
Argument #2' cannot convertobject' expression to type `string'
// Can't put an *object* Type into *string*
GameInformation' does not contain a definition forSpeed'
// You can probably guess that this means that there is no Speed in GameInformation
GameInformation' does not contain a definition for
Endurance'
// You guessed it, no Endurance in GameInformation :)
The best overloaded method match for `UnityEngine.PlayerPrefs.SetString(string, string)' has some invalid arguments
// Based on the other errors, you're probably trying to pass *object* as
// a *string*
基本上,这些错误都归结为一件事:您的 GameInformation 类没有您引用的属性(耐力、速度等(,这会让编译器感到不安。