I’ve been trying to figure out the Rigidbody2D component for Unity 5, as most of the tutorials I’ve watched are for Unity 4. I believe I have it mostly worked out for top-down player movement, but no matter how much I fiddle around I can’t get rid of these last two errors: “Error CS1519 unexpected symbol ‘=’ / ‘(’ in class, struct or interface member declaration.” I can’t find what’s wrong; can anyone give a hand?
using UnityEngine;
using System.Collections;
public class Player_Movement : MonoBehaviour {
public float speed;
rb = GetComponent<Rigidbody2D>(); //this is the line both errors always take me back to
// Update is called once per frame
void FixedUpdate () {
//WASD Movement
if (Input.GetKey (KeyCode.D))
rb.AddForce (Vector2.right * speed);
if (Input.GetKey (KeyCode.A))
rb.AddForce (Vector2.left * speed);
if (Input.GetKey (KeyCode.W))
rb.AddForce (Vector2.up * speed);
if (Input.GetKey (KeyCode.S))
rb.AddForce (Vector2.down * speed);
//Arrow keys movememt
if (Input.GetKey (KeyCode.RightArrow))
Player.transform.Translate(Vector2.right * speed);
if (Input.GetKey (KeyCode.LeftArrow))
Player.transform.Translate(Vector2.left * speed);
if (Input.GetKey (KeyCode.UpArrow))
Player.transform.Translate(Vector2.up * speed);
if (Input.GetKey (KeyCode.DownArrow))
Player.transform.Translate(Vector2.down * speed);
}
}
(Ignore the transform function in the arrow keys, I just haven’t bothered changing that until I figure out what’s going on with WASD.