Home>

I wanted to make a 2D game with Unity and tried to attach a c # script to the sprite.

Error message

First I wrote a simple script and got an error, so this time
After creating the project, I created New Sprite and C # Scrit and tried to attach it to New Sprite without touching the contents at all.

Can't add script component 'NewBehaviourScript' because the script class cannot be found .Make sure that there are no compile errors and that the fie name and class name match.
Applicable source code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NewBehaviourScript: MonoBehaviour
{
    // Start is called before the first frame update
    void Start ()
    {
    }
    // Update is called once per frame
    void Update ()
    {
    }
}

When I looked into it, it was an error due to a mismatch between the class name and the file name, so I tried using copy and paste several times, but I still got the same error.

Supplemental information (FW/tool version etc.)

windows 10
unity 2019.2.14f1
Microsoft Visual Studio Community 2019 Version 16.2.4

  • Answer # 1

    It seems to be a bug in Unity Hub 2.2.0,

    C: \ Program Files \ Unity \ Hub \ Editor \ Version \ Editor \ Data \ Tools \ RoslynScripts \ unity_csc.bat
    Open it with a memo stick, etc. "% APPLICATION_CONTENTS% \ Tools \ Roslyn \ csc"/shared% *

    "% APPLICATION_CONTENTS% \ Tools \ Roslyn \ csc.exe"/shared% *

    It can be avoided by changing to

    .

    Blank Console Error on Empty Project with a Single C # Script-Unity Answers

    Or, if it's OK for Unity2018 series, you should install Unity2018 series version.
    (Since only the Unity2019 version will cause an error)