简体   繁体   中英

Unity3d 2019.3.10 UnityEngine.UI; not found

I want to display the number of coins on the screen, but I have error into my VScode:

The type or namespace name "UI" does not exist in the namespace "UnityEngine"

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

public class Main : MonoBehaviour {
    public Player player;
    public Text coinText;
    public Image[] hearts;
    public Sprite isLife, noneLife;

    void Start() {

    }

    void Update() {
        coinText.text = player.getCoins().ToString();

        Lose();
    }
}

在此处输入图像描述

For Visual Studio Code (VSCode) not detecting UnityEngine.UI, you can follow these steps to solve possible issues.

  1. In Unity, go to Window/Package Manager
  2. Search for "Visual Studio Code Editor"
  3. Downgrade to version 1.2.3 (or upgrade to 1.2.5, seems like 1.2.4 is the problem)
  4. In Window/Package Manager , Search for "Unity UI"
  5. Re-install the package
  6. In Edit/Preferences/External Tools , check the "Registry packages" option
  7. In Edit/Preferences/External Tools , click the "Regenerate project files" button"

If that didn't fix the problem, downgrade "Visual Studio Code Editor" to 1.1.3 instead.
Then you have to manually delete.csproj and.sln files at the root of your project and restart Unity.

From this unity thread:

  • 1) Close Unity and any code editors you have open
  • 2) Make a backup of the Library folder from your project folder to your desktop
  • 3) Delete the Library folder from your project folder
  • 4) Open your project (Unity will rebuild the Library folder)
  • 5) Close Unity
  • 6) Delete the newly generated Library folder
  • 7) Move the Library folder (you backed up earlier) from your desktop back into your project folder
  • 8) Open your project
  • 9) Open one of your scripts UnityEngine.UI should be fine now

I had a same issue. I changed visual studio code editor version to 1.2.1 in Windows > Package Manager > Visual Studio Code Editor section; I hope it helps

  1. Switch to VS Community under External Script Editor.
  2. Regenerate project files
  3. Switch back to VS Code.
  4. DON'T regenerate project files.
  5. Restart everything.

Hi Bro Solved the problem, very simple. Delete Unity Hub.If not solved, download a new version of unity, don't run it with the hub. Then run it with the hub.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM