2014-12-06 87 views
-5

兩個腳本生成由它的外觀這些錯誤,他們列舉如下:團結3D - 錯誤太多

------------------- ------------ GameInformation - 編碼如下: -------------------------- -----

using UnityEngine; 

using 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); 
    } 

}

----------------------------- - 錯誤: -------------------------------

資產/標準 資產/腳本/ SavingAndLoading/SaveInformation.cs(7,67):錯誤 CS0117:GameInformation' does not contain a definition for PlayerLevel」

資產/標準 資產/腳本/ SavingAndLoading/SaveInformation.cs(7,29):錯誤 CS1502 :用於 `UnityEngine.PlayerPrefs.SetInt(字符串,整數)」最好的重載的方法匹配有一些無效 參數

資產/標準 資產/腳本/ SavingAndLoading/SaveInformation.cs(7,29):錯誤 CS1503:參數#2' cannot convert object'表達式到'int'類型

資產/標準 資產/腳本/ SavingAndLoading/SaveInformation.cs(8,69):錯誤 CS0117:GameInformation' does not contain a definition for PlayerName」

資產/標準 資產/腳本/ SavingAndLoading/SaveInformation.cs(8, 29):錯誤 CS1503:參數#2' cannot convert對象 '表達鍵入 '字串'

資產/標準 資產/腳本/ SavingAndLoading/SaveInformation。CS(9,64):錯誤 CS0117:GameInformation' does not contain a definition for速度」

資產/標準 資產/腳本/ SavingAndLoading/SaveInformation.cs(9,29):錯誤 CS1502:最好重載方法 匹配`UnityEngine .PlayerPrefs.SetString(字符串,字符串) '已經一些無效 參數

資產/標準 資產/腳本/ SavingAndLoading/SaveInformation.cs(9,29):錯誤 CS1503:參數#2' cannot convert對象' 表達鍵入 `string'

資產/標準 資產/腳本/ SavingAndLoading/SaveInformation.cs(10,68):錯誤 CS0117:GameInformation' does not contain a definition for 耐力」

資產/標準 資產/腳本/ SavingAndLoading/SaveInformation.cs(10,29) :錯誤 CS1502:用於 `UnityEngine.PlayerPrefs.SetString(字符串,字符串)最好重載的方法匹配」具有一些無效 參數

資產/標準 資產/腳本/ SavingAndLoading/SaveInformation.cs(10,29 ):錯誤 CS1503:參數#2' cannot convert對象 '表達鍵入 '字串'

資產/標準 資產/腳本/ SavingAndLoading/SaveInformation.cs(11,67):錯誤 CS0117:GameInformation' does not contain a definition for強度」

資產/標準 資產/腳本/SavingAndLoading/SaveInformation.cs(11,29):錯誤 CS1502:用於 `UnityEngine.PlayerPrefs.SetString(字符串,字符串,最好重載方法匹配)」具有一些無效 參數

資產/標準 個資產/腳本/ SavingAndLoading/SaveInformation.cs(11,29):錯誤 CS1503:參數#2' cannot convert對象 '表達鍵入 '字串'

資產/標準 資產/腳本/ SavingAndLoading/SaveInformation.cs(12 ,65):錯誤 CS0117:GameInformation' does not contain a definition for健康」

資產/標準 資產/腳本/ SavingAndLoading/SaveInformation.cs(12,29):錯誤 CS1502:用於 `UnityEngine.PlayerPrefs最好重載方法匹配。 SetString(string,string)'有一些無效 參數

資產/標準 資產/腳本/ SavingAndLoading/SaveInformation.cs(12,29):錯誤 CS1503:參數#2' cannot convert對象 '表達鍵入 '字串'

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

請回答時,請記住,我是比較新的編碼。謝謝!

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

回答

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類沒有,你引用的屬性(耐力,速度等),這讓編譯器感到不安。

+0

所以,如果我需要解決這個問題,我會... – 2014-12-06 21:06:24

+0

我該如何解決它? – 2014-12-06 22:18:07

+0

從我的答案可以推斷,可以添加屬性或刪除對不存在的屬性的引用。我的回答的第二個含義是,如果你*不能*修復它,你*可以*學習。以下是一組教程,以便您可以實際學習如何編程:http://www.tutorialspoint.com/csharp/index.htm – 2014-12-06 22:37:56