GetComponent<Rigidbody2D>() not working

Hello there!
I have an issue regarding GetComponent<'Rigidbody2D>() for launching the ball. Despite the code being identical to the one in the course, the line above is recognized as an error.

Hovering over it indicates that: “An object reference is required for the non-static field method or property.”
Similarly, unity’s console return "Assets\Scripts\Ball.cs(32,13): error CS0120: An object reference is required for the non-static field, method, or property ‘Component.GetComponent()’.

Here is the whole code:

Any help would be very appreciated ^^

Hi Mathieu,

Welcome to our community! :slight_smile:

Remove the static keyword in line 28. Did this fix it?


See also:

1 Like

Just noticed it myself ! It was indeed the problem (autofill on Method creation probably).

Thank you for the response !

You’re welcome. :slight_smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms