我想改變團結球員的速度,但我不能從另一個腳本訪問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?)
我試過出頭,但我我感到困擾的是,我搜索的每個地方都爲我提供了一種不起作用的解決方案。任何人都可以幫我嗎?
你得到了什麼錯誤?你必須更具體。 – 2014-10-20 16:00:43
你的球員被標記爲「球員」。代碼尋找標記爲「播放器」的對象。如果錯誤是玩家空引用,那麼你沒有一個玩家對象標記爲玩家。如果錯誤在第2行,那麼沒有CharacterMotor組件(腳本)附加到播放器。 – 2014-10-20 16:13:12
我只是把整個錯誤。該對象被標記爲播放器並且它具有該組件。 – 2014-10-20 18:43:37