C# Unity 3D-错误太多
从外观上看,有两个脚本正在生成这些错误,如下所示: ---------------- 游戏信息-编码如下所示: ---------------- 使用系统集合 公共类游戏信息:单一行为{C# Unity 3D-错误太多,c#,unity3d,C#,Unity3d,从外观上看,有两个脚本正在生成这些错误,如下所示: ---------------- 游戏信息-编码如下所示: ---------------- 使用系统集合 公共类游戏信息:单一行为{ void Awake(){ DontDestroyOnLoad (transform.gameObject); } public static string PlayerName{ get; set; } public static int PlayerLevel{ get; set; } publi
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; }
}
----------------
另一个脚本是SaveInformation:
----------------
使用系统集合
公共类存储信息{
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);
}
}
----------------
错误:
----------------
资产/标准
资产/脚本/SavingAndLoading/SaveInformation.cs7,67:错误
CS0117:GameInformation'不包含的定义
PlayerLevel'
资产/标准
资产/脚本/SavingAndLoading/SaveInformation.cs7,29:错误
CS1502:最适合的重载方法
`UnityEngine.PlayerPrefs.SetIntstring,int'具有一些无效的
论据
资产/标准
资产/脚本/SavingAndLoading/SaveInformation.cs7,29:错误
CS1503:参数2“无法将Object”表达式转换为“int”类型
资产/标准
资产/脚本/SavingAndLoading/SaveInformation.cs8,69:错误
CS0117:GameInformation'不包含的定义
PlayerName'
资产/标准
资产/脚本/SavingAndLoading/SaveInformation.cs8,29:错误
CS1503:参数2“无法将对象”表达式转换为类型
`字符串'
资产/标准
资产/Scripts/SavingAndLoading/SaveInformation.cs9,64:错误
CS0117:游戏信息“不包含速度的定义”
资产/标准
资产/脚本/SavingAndLoading/SaveInformation.cs9,29:错误
CS1502:最适合的重载方法
`UnityEngine.PlayerPrefs.SetString字符串,字符串“”具有一些无效
论据
资产/标准
资产/脚本/SavingAndLoading/SaveInformation.cs9,29:错误
CS1503:参数2“无法将对象”表达式转换为类型
`字符串'
资产/标准
资产/脚本/SavingAndLoading/SaveInformation.cs10,68:错误
CS0117:GameInformation'不包含的定义
耐力'
资产/标准
资产/脚本/SavingAndLoading/SaveInformation.cs10,29:错误
CS1502:最适合的重载方法
`UnityEngine.PlayerPrefs.SetString字符串,字符串“”具有一些无效
论据
资产/标准
资产/脚本/SavingAndLoading/SaveInformation.cs10,29:错误
CS1503:参数2“无法将对象”表达式转换为类型
`字符串'
资产/标准
资产/脚本/SavingAndLoading/SaveInformation.cs11,67:错误
CS0117:游戏信息“不包含强度的定义”
资产/标准
资产/脚本/SavingAndLoading/SaveInformation.cs11,29:错误
CS1502:最适合的重载方法
`UnityEngine.PlayerPrefs.SetString字符串,字符串“”具有一些无效
论据
资产/标准
资产/脚本/SavingAndLoading/SaveInformation.cs11,29:错误
CS1503:参数2“无法将对象”表达式转换为类型
`字符串'
资产/标准
资产/脚本/SavingAndLoading/SaveInformation.cs12,65:错误
CS0117:游戏信息“不包含健康的定义”
资产/标准
资产/脚本/SavingAndLoading/SaveInformation.cs12,29:错误
CS1502:最适合的重载方法
`UnityEngine.PlayerPrefs.SetString字符串,字符串“”具有一些无效
论据
资产/标准
资产/脚本/SavingAndLoading/SaveInformation.cs12,29:错误
CS1503:参数2“无法将对象”表达式转换为类型
`字符串'
----------------
请记住,当回答我是相当新的编码。谢谢
----------------在编程世界中,这些都是非常基本的错误,如果你理解它们,你会发现进步要容易得多,而不仅仅是下载脚本并希望它们都插在一起。下面我介绍了每个错误的原因,让你开始学习:
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类没有引用耐力、速度等的属性,这让编译器感到不安。从我的回答中可以推断,要么添加属性,要么删除对不存在的属性的引用eply是说,如果你不能修复它,你可以学习。这里有一组教程,你可以学习如何编程:是的,但是你说添加属性是什么意思!如何添加属性,或者我如何添加属性!?
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);
}
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*