Amstergo
Amstergo

Reputation: 43

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();
    }
}

enter image description here

Upvotes: 3

Views: 14510

Answers (5)

Abdulkadır Gur
Abdulkadır Gur

Reputation: 1

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.

Upvotes: 0

Saleh Hosseini
Saleh Hosseini

Reputation: 523

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.

Upvotes: 9

AmyyazdaN
AmyyazdaN

Reputation: 311

  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.

Upvotes: 1

Barış Can Yılmaz
Barış Can Yılmaz

Reputation: 735

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

Upvotes: 0

Hamid Yusifli
Hamid Yusifli

Reputation: 10137

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

Upvotes: 3

Related Questions