2014-10-20 66 views
-1

我想改變團結球員的速度,但我不能從另一個腳本訪問CharacterMotor。我搜索的實習,我發現這(對於C#):如何改變CharacterMotor在Unity

Player = GameObject.FindGameObjectsWithTag("Player")[0]; 
Player.GetComponent("CharacterMotor"). 
     CharacterMotorMovement.maxForwardSpeed = 6.0; 

但是,這並不工作,我得到的錯誤:

Assets/Scripts/MainScript.cs(60,63): error CS1061: 
Type `UnityEngine.Component' does not contain a definition for 
`CharacterMotorMovement' and no extension method 
`CharacterMotorMovement' of type `UnityEngine.Component' could be 
found (are you missing a using directive or an assembly reference?) 

我試過出頭,但我我感到困擾的是,我搜索的每個地方都爲我提供了一種不起作用的解決方案。任何人都可以幫我嗎?

+0

你得到了什麼錯誤?你必須更具體。 – 2014-10-20 16:00:43

+0

你的球員被標記爲「球員」。代碼尋找標記爲「播放器」的對象。如果錯誤是玩家空引用,那麼你沒有一個玩家對象標記爲玩家。如果錯誤在第2行,那麼沒有CharacterMotor組件(腳本)附加到播放器。 – 2014-10-20 16:13:12

+0

我只是把整個錯誤。該對象被標記爲播放器並且它具有該組件。 – 2014-10-20 18:43:37

回答

-1

現在,因爲它說你必須重視CharacterMovement腳本Player對象。

+0

您的建議可能正確也可能不正確,但這並不能解決問題中顯示的編譯錯誤。 – 2014-10-22 09:59:12

+0

看起來它不是一個類型轉換錯誤。它一定是這樣的。 不能將類型'UnityEngine.Component'隱式轉換爲'UnityEngine.CharacterMovement'。一個顯式轉換存在(是否缺少強制轉換? 這是不是一個好的行爲來投票了試圖幫助而沒有explenation用戶。該帖已被編輯。 – 2014-10-22 22:02:17

+0

該組件是'CharacterMotor',不'CharacterMovement '。 – 2014-10-29 08:25:00