Search Unity

The Referenced Script on this behaviour is missing! error code

Discussion in 'Scripting' started by DropTeadFred, Apr 11, 2021.

  1. DropTeadFred

    DropTeadFred

    Joined:
    Apr 9, 2021
    Posts:
    1
    my code is


    using UnityEngine;

    public class MoveCharacter : MonoBehaviour
    {
    public float MovementSpeed = 1;
    public float JumpForce = 1;

    private Rigidbody2D _rigidbody;

    private void Start()
    {
    _rigidbody = GetComponent<Rigidbody2D>();
    }

    private void Update()
    {
    var movement = Input.GetAxis("Horizontal");
    transform.position += new Vector3(movement, 0, 0) * Time.deltaTime * MovementSpeed;

    if (Input.GetButtonDown("Jump") && Mathf.Abs(_rigidbody.velocity.y) < 0.001f)
    {
    _rigidbody.AddForce(new Vector2(0, JumpForce), ForceMode2D.Impulse);
    }
    }
    }
    and for some reason when i put this into unity and play it says
    The Referenced Script on this behaviour is missing! error code
    for some reason??
     

    Attached Files:

  2. GroZZleR

    GroZZleR

    Joined:
    Feb 1, 2015
    Posts:
    3,201
    Your class is called MoveCharacter but your file is called MovePlayer. They must match.