Home > Back-end >  error CS0246: The type or namespace name 'UnityEngine' could not be found
error CS0246: The type or namespace name 'UnityEngine' could not be found

Time:12-02

I'm trying to make a simple game using unity and C# with vs code. But when I try to build and run the program; it shows "error CS0246: The type or namespace name 'UnityEngine' could not be found (are you missing a using directive or an assembly reference?)"

and

" error CS0246: The type or namespace nam e 'MonoBehaviour' could not be found (are you missing a using directive or an assembly reference?)"

I tried to fix the error "preferences -> External tools -> External script editors -> vs code" but its not work.

But c# works in the random program correctly. When I run any unity scripts; its show error.

code sample in the below:

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

public class test : MonoBehaviour
{
    public string ab = "sh";
    // Start is called before the first frame update
    void Start()
    {
        
        
    }

    // Update is called once per frame
    void Update()
    {
        Debug.Log(ab);
        
    }
}

CodePudding user response:

Open "visual studio installer" and click on "Modify" on the version (that has been selected in "Unity>Edit>Preferences>External Tools>External Script Editor"), after clicking on modify make sure under "Workloads>Gaming" -> "Game development with Unity" is checked(if not do so). After that close all windows of unity and visual studio and open again your project and go to "Unity>Edit>Preferences>External Tools" click on "Regenerate project files" button. That'll resolve your issue!

  • Related