S
S
Sergey Goretov2021-01-04 13:47:44
Unity
Sergey Goretov, 2021-01-04 13:47:44

How to fix "No MonoBehavior scripts in the file, or their names do not match the file name" Unity C# error?

Here is my script:

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

public class Player : MonoBehaviour
{
    public float speed;

    private Rigidbody2D rb;
    private Vector2 moveInput;
    private Vector2 moveVelocity;

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

    void Update()
    {
        moveInput = new Vector2(Input.GetAxisRaw(Horizontal)
        moveVelocity = moveInput.normalized * speed;
    }

    void FixedUpdate()
    {
        rb.MovePosition(rb.position + moveVelocity * Time.fixedDeltaTime);
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vasily Bannikov, 2021-01-04
@vabka

If you throw an error message into Google translator, then everything becomes clear:

The file does not contain MonoBehaviour scripts or their names do not match the file name

This is a Unity-specific error, so the C# tag is not needed here.
Let me remind you that it is not clear why the unit calls classes scripts

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question