I’m trying to make a 2d object move around freely but I keep receiving the error with my code: error CS0120: An object reference is required to access non-static member `UnityEngine.Rigidbody2D.velocity’ . I’m not certain what’s causing it or how to really fix it, code below if anyone can help me understand why it is my rigid body doesn’t want to move.
using UnityEngine;
/// <summary>
/// Player controller and behavior
/// </summary>
public class PlayerScript : MonoBehaviour
{
/// <summary>
/// 1 - The speed of the ship
/// </summary>
public Vector2 speed = new Vector2(50, 50);
// 2 - Store the movement
private Vector2 movement;
void Update()
{
// 3 - Retrieve axis information
float inputX = Input.GetAxis("Horizontal");
float inputY = Input.GetAxis("Vertical");
// 4 - Movement per direction
movement = new Vector2(
speed.x * inputX,
speed.y * inputY);
}
void FixedUpdate()
{
// 5 - Move the game object
Rigidbody2D.velocity = movement;
}
}
For more information I’m attempting to follow this tutorial that was written for unity 4.3 and I am currently using unity 5 if that helps.