error CS0131: The left-hand side of an assignment must be a variable, a property or an indexer

I’m getting tired of error after error. Here is my code in Unity(the only script I have in my game with errors),

using UnityEngine;

public class Obstacle : MonoBehaviour
public Vector2 velocity = new Vector2 (-4, 0);

// Use this for initialization
void Start()
	GetComponent<Rigidbody2D> = velocity;


I have no idea how to fix this problem, I looked everywhere and still no fix…
If I can get a quick response that would be well apreciated

You’re not setting the velocity correctly in your script. You’re attempting to assign a Vector2 named velocity to your Rigidbody, rather than your Rigidbody’s velocity variable.

As gjf stated, it is better to define a reference to the rigidbody before using it, rather than gathering that data with every use. The script offered is right on the money; to prevent confusion, it would be prudent to change your “velocity” variable’s name. Additionally, the key difference besides is the line:

_rigidbody2D.velocity = MyVelocity;

This is using the public variable you defined in the Rigidbody’s velocity value, whereas your line:

GetComponent<Rigidbody2D> = velocity;

This is attempting the use the public variable you defined, not in the Rigidbody’s velocity, but in place of the Rigidbody itself.