Error on Control Script

New to Unity and C#

Trying to follow a tutorial on building a 2D game.

i have this script:

 using UnityEngine;
    using System.Collections;
    
    public class BeppoScript : MonoBehaviour {
    
    	// Use this for initialization
    	public Camera cam;
    	void Start () {
    		if (cam == null) {
    			cam = Camera.main;
    		}
    	
    	}
    	
    	// Update is called once per physics timestamp
    	void FixedUpdate () {
    		Vector3 rawpos = cam.ScreenToWorldPoint (Input.mousePosition);
    		Vector3 tgtpos = new Vector3 (rawpos.x, 0.0f, 0.0f);
    		Rigidbody2D.MovePosition (tgtpos);
    		
    	}
    }

but it gives an error in the engine:

Assets/Scripts/BeppoScript.cs(19,29): error CS0120: An object reference is required to access non-static member `UnityEngine.Rigidbody2D.MovePosition(UnityEngine.Vector2)'

Not sure what the fix is.

sidenote:
That MonoDevelop thing doesn’t respond to any inputs outside of the text editor part; i can’t close it or access any of the options.
If anyone has a fix for that, it would be great.

You can change

Rigidbody2D.MovePosition (tgtpos);

to

this.GetComponent<Rigidbody2D>().MovePosition (tgtpos);

add this line before Start()

private Rigidbody2D _rb;

add this line in Start()

_rb = GetComponent<Rigidbody2D>();

then change line 19 to

_rb.MovePosition (tgtpos);

previous versions of unity had shortcuts to certain components, which more recent versions don’t (to make it clearer what unity is doing behind the scenes). it’s likely that the tutorial/code you got this from used a previous version.

hope that helps.