S
S
SDHOPS2015-07-26 13:48:00
Programming
SDHOPS, 2015-07-26 13:48:00

Unity3D: Error CS0120 - An object ...?

When typing a script, in Unity 5 it gives an error CS0120:
Assets/Player/Button.cs(29,37): error CS0120: An object reference is required to access non-static member `UnityEngine.Rigidbody2D.AddForce(UnityEngine.Vector2, UnityEngine .ForceMode2D)'
Here's a screenshot of the script: af5154763efe413686255ce41dddacd6.PNG
Help, where did I make a mistake?
PS: This is a development for an Android game, at first I did the controls, everything was fine, but as soon as I added the Jump, an error appeared...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Espleth, 2015-07-26
@SDHOPS

Something is not good with your materiel, go to teach.
Create an instance of the Rigidbody2d class, let it be rb for example.
Then in Start() rb = GetComponent();
Then write where necessary rb.AddForce(...);
UPD: I read the script, and you, apparently, also tried to make the button move.
In your case, in Start() you need to write rb = player.GetComponent();
UPD2:
Toaster doesn't display any signs
This is how it should be

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question