I have been running via an online walkthrough to learn the basics of creating a basic 2D game via Unity. However, since this walkthrough had been written a while ago I have been having issues regarding the code. Can anyone help me out?
using UnityEngine;
public class Player : MonoBehaviour
{
public Vector2 speed = new Vector2(50, 50);
private Vector2 movement;
void Update ()
{
float inputX = Input.GetAxis ("Horizontal");
float inputY = Input.GetAxis ("Vertical");
movement = new Vector2(
speed.x * inputX,
speed.y * inputY);
}
void FixedUpdate()
{
rigidbody2D.velocity = movement;
}
}
As another source I have included the link to the web page I have been working from below.
@GiggyLapisar
Try this
using UnityEngine;
public class Player : MonoBehaviour
{
public Vector2 speed = new Vector2 (50, 50);
private Vector2 movement;
private Rigidbody2D playerRigid;
void Start ()
{
playerRigid = GetComponent<Rigidbody2D> ();
}
void Update ()
{
float inputX = Input.GetAxis ("Horizontal");
float inputY = Input.GetAxis ("Vertical");
movement = new Vector2 (
speed.x * inputX,
speed.y * inputY);
}
void FixedUpdate ()
{
playerRigid.velocity = movement;
}
}
The code is untested but should work for you