The referenced script on this Behaviour is missing! | Help Fast :/

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Playermovement : MonoBehaviour
{
public float speed = 6f;
public float gravity = 20f;

CharacterController controller;

float horizontal;
float vertical;

Vector3 moveDirection = Vector3.zero;
// Start is called before the first frame update
void Start()
{
    controller = GetComponent<CharacterController>();
}

// Update is called once per frame
void Update()
{
    horizontal = Input.GetAxis("Horizontal");
    vertical = Input.GetAxis("Vertical");
    if (controller.isGrounded)
    {

        moveDirection = new Vector3(horizontal, 0.0f, vertical);
        moveDirection *= speed;
    }

    moveDirection.y -= gravity * Time.deltaTime;
    controller.Move(moveDirection * Time.deltaTime);
}

}

,using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Playermovement : MonoBehaviour
{
public float speed = 6f;
public float gravity = 20f;

CharacterController controller;

float horizontal;
float vertical;

Vector3 moveDirection = Vector3.zero;
// Start is called before the first frame update
void Start()
{
    controller = GetComponent<CharacterController>();
}

// Update is called once per frame
void Update()
{
    horizontal = Input.GetAxis("Horizontal");
    vertical = Input.GetAxis("Vertical");
    if (controller.isGrounded)
    {

        moveDirection = new Vector3(horizontal, 0.0f, vertical);
        moveDirection *= speed;
    }

    moveDirection.y -= gravity * Time.deltaTime;
    controller.Move(moveDirection * Time.deltaTime);
}

}

You most likely renamed your script while it was already attached to a gameobject / prefab.

Make sure:

  • The file name of your script file matches exactly your class name. Since you named your class Playermovement your file has to be named Playermovement.cs. Note the casing has to match as well
  • If you renamed your script after you attached it to a gameobject, make sure to remove the old instance and re-attach the new one.