I’m trying to build a simple code, just for testing purposes, and it won’t let me.
In editor mode the game works fine but when I try to build, these messages show up:
‘Assets/PlayerController.cs(3,33): error CS0246: The type or namespace name MonoBehaviour' could not be found. Are you missing an assembly reference?' 'Assets/PlayerController.cs(4,9): error CS0246: The type or namespace name Rigidbody2D’ could not be found. Are you missing an assembly reference?’
Any ideas?
using UnityEngine;
public class PlayerController : MonoBehaviour {
public Rigidbody2D rb;
public float currentSpeed = 0f;
public float maxSpeed = 5f;
public float jumpPower = 10f;
void FixedUpdate()
{
Move();
}
// Update is called once per frame
void Update ()
{
if (Input.GetKeyDown(KeyCode.Space)) Jump();
if (Input.GetKey(KeyCode.LeftShift)) currentSpeed = Input.GetAxis("Horizontal") * maxSpeed * 2;
else currentSpeed = Input.GetAxis("Horizontal") * maxSpeed;
}
void Jump()
{
rb.velocity = new Vector2(rb.velocity.x, jumpPower);
}
void Move()
{
rb.velocity = new Vector2(currentSpeed, rb.velocity.y);
}
}