Component.GetComponent<T>() 是一种方法,在给定的上下文中无效

Component.GetComponent<T>() is a method, which is not valid in the given context

如果游戏中发生某些事情,我正在尝试关闭一个实例化预制克隆的重力。我有这个:

public class Controller : MonoBehaviour   

   public Transform randomcoin;

   private void Start()

      if ( ... ) 
          { randomcoin.GetComponent<Rigidbody>.useGravity = false; }

这给了我这个错误:

Component.GetComponent<T>() is a method, which is not valid in the given context

有谁知道我该如何解决这个问题?

您在 randomcoin.GetComponent<Rigidbody> 中缺少 () 它应该是这样的: randomcoin.GetComponent<Rigidbody>()