2016-03-31 55 views
-2

enter image description hereBCE0019:xxx是不是「對象」

我輸入aniPlay=GetComponent("aniSprite"),但似乎沒有工作的一員,我怎麼可以修改?

+0

不確定它是否與JavaScript相同,但在C#中,您將編寫'aniPlay = GetComponent ();'。也許試試? –

+0

我試過了,在()中我應該添加一些東西,導致它有另一個問題aniPlay = GetComponent (); } BCE0043:意外的令牌:)。 – Cathy

+0

哦,對不起,在Unity手冊中檢查過(你也應該:)),看起來應該是'aniPlay = GetComponent(aniSprite);'看到這裏:http://docs.unity3d.com/ScriptReference/GameObject.GetComponent。 html –

回答

0

嘗試:

privat var aniPlay : aniSprite; 

function Start() { 
    aniPlay = gameObject.GetComponent(aniPlay); 
} 
+0

但我遇到了另一個問題aniPlay = gameObject.GetComponent(aniPlay); } BCE0023:未找到適用於參數列表'(aniSprite)'的'UnityEngine.GameObject.GetComponent'版本。 aniSprite可能有問題嗎?我不知道。 – Cathy

0
aniPlay = gameObject.GetComponent(aniPlay); 

這是GetComponent的正確形式,但對於這個工作,你需要確保以下幾點:

  1. aniPlay是一個實際的名稱一個工作類
  2. 指定的遊戲對象有一個該類的實例附加到它
+0

所以我遇到了這個問題BCE0023:找不到適合版本的'UnityEngine.GameObject.GetComponent'的參數列表'(aniSprite)'。是因爲指定的gameObject沒有附加該類的實例?對不起,我很難理解JavaScript,因爲我從來沒有學過它。 – Cathy

+0

我剛剛注意到,你有類和變量的相同名稱(改變大寫/小寫),我想你可能會混淆編譯器,嘗試改變它,讓我知道發生了什麼。 –

+0

謝謝你的建議,我仍然不知道爲什麼,但我剛剛刪除了aniSprite和playerController,重新輸入它們,然後我發現它工作!非常感謝! (≧∇≦)ノ – Cathy