Question by
Scrummer · Feb 23, 2017 at 03:46 PM ·
c#2dplayercontroller
My Player Controllercode isn't working
I'm trying to do the 2D UFO tutorial, and every time I enter in my code it says "The referenced 'player' game object is missing" And whenever I try to test it, the player doesn't move. This is my code.
using System.Collections; using UnityEngine;
public class CompletePlayerController : MonoBehaviour {
public float speed;
private Rigidbody2D rb2d;
// Use this for initialization
void Start () {
rb2d = GetComponent<Rigidbody2D> ();
}
// Update is called once per frame
void FixedUpdate () {
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
Vector2 movement = new Vector2 (moveHorizontal, moveVertical);
rb2d.AddForce (movement * speed);
}
Comment
Never $$anonymous$$d, I got it all fixed! Thanks everyone!
Answer by dzne_weiss · Feb 23, 2017 at 04:02 PM
Did you set a "speed" value in the editor? Because you did not set it in the script
$$anonymous$$ind sharing what you did wrong / how you fixed it?
As it turns out, in the rigidbody2d asset on my player character, I had the "Simulated" box in-checked.