Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

unity3d

unity5

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?

like image 484
lakeviking Avatar asked Sep 19 '17 14:09

lakeviking


1 Answers

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

like image 186
Fiffe Avatar answered Sep 24 '22 02:09

Fiffe