【问题标题】:Translation UnityScript to C#: GetComponent将 UnityScript 翻译成 C#:GetComponent
【发布时间】:2015-09-17 13:48:55
【问题描述】:

我正在努力将最初使用 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# 中如何处理?

【问题讨论】:

    标签: c# unity3d unityscript


    【解决方案1】:
    characterController = GetComponent(CharacterController);
    

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

    characterController = GetComponent<CharacterController>();
    

    关于另一条线,中间有一个额外的点。应该是:

    GetComponent<Animation>().Stop();
    

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

    【讨论】:

    • 感谢您的帮助!它的工作:) 我还有一些问题要问你,这可能吗?
    • @PokeRwOw:很高兴这对你有用!如果您还有其他问题,我建议您在这里打开新帖子,以便很多人可能会帮助您。干杯。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-11
    • 1970-01-01
    • 1970-01-01
    • 2015-01-13
    • 1970-01-01
    相关资源
    最近更新 更多