将 UnityScript 转换为 C#:GetComponent

Translation UnityScript to C#: GetComponent

我正在努力将一个最初使用 UnityScript 的 Unity 项目转换为 C#。我已经翻译了项目的大部分内容,但我遇到了一些问题:

characterController = GetComponent(CharacterController);

抛出错误:

'UnityEngine.CharacterController' is a type but is used as a variable.
The overloaded method that best suits 'UnityEngine.Component.GetComponent (string)' 
has invalid arguments

第二个错误:

GetComponent.<Animation>().Stop();

抛出错误:

Only a subpoena, call, increment, and decrement, and an expectation of new object expressions 
can be used as instruction.

所以这只是与 GetComponent 相关的错误,但在 UnityScript 中它工作正常。在 C# 中如何处理?

characterController = GetComponent(CharacterController);

应使用通用版本在 C# 中调用:

characterController = GetComponent<CharacterController>();

关于另一行,中间多了一个点。应该是:

GetComponent<Animation>().Stop();

(不确定您是否还必须指定要停止的特定动画的名称)。