方法调用甚至不会编译

-1 c#

只是学习C#作为Unity脚本.以下内容无法编译.通过将代码置于"无效更新"中我已经解决了这个问题,但我显然错过了一些东西.我在编译器失败的地方发表评论.

任何启蒙都将不胜感激!

using UnityEngine;
using System.Collections;

public class ThrottleControl : MonoBehaviour {
    public float 
        ThrottlePosition,
        ThrottleEffectiveness,
        ThrottleReturnSpeed;

    private string ThrottleStr = "Throttle";

    void GetThrottlePosition()
    {
        if (Input.GetButtonDown (ThrottleStr)) 
        {
            //code here eliminated for clarity
        }
    } // GetThrottle Position


    // Use this for initialization
    void Start () {
        ThrottleEffectiveness = 0.1f;
    }

    // Update is called once per frame
    void Update () { //compiler error here about allowed statements
        GetThrottlePosition; 
    }
}
Run Code Online (Sandbox Code Playgroud)

只有赋值,调用,递增,递减,等待和新对象表达式才能用作语句

Jus*_*ony 5

GetThrottlePosition 需要用空的parens来调用

void Update () 
{
    GetThrottlePosition(); 
}
Run Code Online (Sandbox Code Playgroud)