Unity 3D - 错误太多

时间:2014-12-06 16:07:25

标签: c# unity3d

两个脚本通过外观生成这些错误,它们列在下面:

------------------------------- GameInformation - 下面列出的编码: -------------------------------

using UnityEngine;

使用System.Collections;

公共课GameInformation:MonoBehaviour {

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: -------------------------------

using UnityEngine;

使用System.Collections;

公共类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);
    }

}

------------------------------- 错误: -------------------------------

  

资产/标准   Assets / Scripts / SavingAndLoading / SaveInformation.cs(7,67):错误   CS0117:GameInformation' does not contain a definition for PlayerLevel'

     

资产/标准   Assets / Scripts / SavingAndLoading / SaveInformation.cs(7,29):错误   CS1502:最佳重载方法匹配   `UnityEngine.PlayerPrefs.SetInt(string,int)'有一些无效   参数

     

资产/标准   Assets / Scripts / SavingAndLoading / SaveInformation.cs(7,29):错误   CS1503:参数#2' cannot convert object'表达式,用于键入`int'

     

资产/标准   Assets / Scripts / SavingAndLoading / SaveInformation.cs(8,69):错误   CS0117:GameInformation' does not contain a definition for PlayerName'

     

资产/标准   Assets / Scripts / SavingAndLoading / SaveInformation.cs(8,29):错误   CS1503:要键入的参数#2' cannot convert object'表达式   `字符串“

     

资产/标准   Assets / Scripts / SavingAndLoading / SaveInformation.cs(9,64):错误   CS0117:GameInformation' does not contain a definition for速度'

     

资产/标准   Assets / Scripts / SavingAndLoading / SaveInformation.cs(9,29):错误   CS1502:最佳重载方法匹配   `UnityEngine.PlayerPrefs.SetString(string,string)'有一些无效   参数

     

资产/标准   Assets / Scripts / SavingAndLoading / SaveInformation.cs(9,29):错误   CS1503:要键入的参数#2' cannot convert object'表达式   `字符串“

     

资产/标准   Assets / Scripts / SavingAndLoading / SaveInformation.cs(10,68):错误   CS0117:GameInformation' does not contain a definition for 耐力'

     

资产/标准   Assets / Scripts / SavingAndLoading / SaveInformation.cs(10,29):错误   CS1502:最佳重载方法匹配   `UnityEngine.PlayerPrefs.SetString(string,string)'有一些无效   参数

     

资产/标准   Assets / Scripts / SavingAndLoading / SaveInformation.cs(10,29):错误   CS1503:要键入的参数#2' cannot convert object'表达式   `字符串“

     

资产/标准   Assets / Scripts / SavingAndLoading / SaveInformation.cs(11,67):错误   CS0117:GameInformation' does not contain a definition for力量'

     

资产/标准   Assets / Scripts / SavingAndLoading / SaveInformation.cs(11,29):错误   CS1502:最佳重载方法匹配   `UnityEngine.PlayerPrefs.SetString(string,string)'有一些无效   参数

     

资产/标准   Assets / Scripts / SavingAndLoading / SaveInformation.cs(11,29):错误   CS1503:要键入的参数#2' cannot convert object'表达式   `字符串“

     

资产/标准   Assets / Scripts / SavingAndLoading / SaveInformation.cs(12,65):错误   CS0117:GameInformation' does not contain a definition for健康'

     

资产/标准   Assets / Scripts / SavingAndLoading / SaveInformation.cs(12,29):错误   CS1502:最佳重载方法匹配   `UnityEngine.PlayerPrefs.SetString(string,string)'有一些无效   参数

     

资产/标准   Assets / Scripts / SavingAndLoading / SaveInformation.cs(12,29):错误   CS1503:要键入的参数#2' cannot convert object'表达式   `字符串“

-------------------------------

在回复时我请记住,我对编码很新。谢谢!

-------------------------------

1 个答案:

答案 0 :(得分:3)

在编程领域,这些都是非常基本的错误,如果您理解它们,您会发现它更容易进步,而不仅仅是下载脚本并希望它们全部插在一起。下面我已经描述了每个错误导致您入门的原因:

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类没有你引用的属性(耐力,速度等),这会让编译器感到不安。