Im getting this error: An object reference is required to access non-static member`UnityEngine.Component.rigidbody2D'

Hello, I have the following code within the update function (c#):

if(Input.GetKey(KeyCode.UpArrow))
		{
			rigidbody2D.velocity.y = speed;
		}

and I am getting this error:

Assets/player.cs(16,32): error CS0120: An object reference is required to access non-static member`UnityEngine.Component.rigidbody2D’

Can anyone assist? thanks

1 Answer

1

Do you have this code inside a static function? That’s likely your problem. Static functions are associated with the class not with a component on a specific game object.