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

时间:2017-09-19 14:54:36

标签: c# unity3d unity5

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

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

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

1 个答案:

答案 0 :(得分:7)

randomcoin.GetComponent<Rigidbody>中你遗失了() 它应该是这样的: randomcoin.GetComponent<Rigidbody>()