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

Viewed 11058

I'm trying to turn off the gravity for one instantiated prefab clone, if something in the game happens. I have this:

public class Controller : MonoBehaviour   

   public Transform randomcoin;

   private void Start()

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

This gives me this error:

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

Does anyone know how I can fix this?

1 Answers

You're missing () in randomcoin.GetComponent<Rigidbody> It should be like this: randomcoin.GetComponent<Rigidbody>()

Related