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.
In Unity, go to Window/Package Manager
Search for "Visual Studio Code Editor"
Downgrade to version 1.2.3 (or upgrade to 1.2.5, seems like 1.2.4 is the problem)
In Window/Package Manager, Search for "Unity UI"
Re-install the package
In Edit/Preferences/External Tools, check the "Registry packages" option
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
Switch to VS Community under External Script Editor.
Regenerate project files
Switch back to VS Code.
DON'T regenerate project files.
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.
Related
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Driver : MonoBehaviour
{
void Start()
{
}
void Update()
{
// transform.Rotate(0,0,0.1f);
transform.Translate(0,.01f,0);
}
}
above is my code. If I add anything incorrectly, no error appears. It appears to be a problem with omnisharp. I have tried reinstalling, fidgeting with the settings, and installing older versions of the C# extension. However, no matter what I change, errors do not appear as I code.
VS Code cannot automatically complete the code or check errors, and the plugin fails.
The following steps are helpful:
First make sure the plugins are installed.
List of plugins:
Debugger for Unity.
Unity Tools.
Unity Colde Snippets.
Make sure the development environment is complete.
An incomplete development environment can also cause this problem. It is also possible that the .net version created by the project does not match the .net version of the development environment.
Solution:
2.1. Use a text editor to open the file with the extension csproj in the root directory of the project.
2.2. Ctrl + F Search "TargetFrameworkVersion" keyword, you can see the information "v4.7.1". This means that your computer lacks the 4.7.1 version of .net Framework, and different computers default Versions may vary.
2.3. Microsoft official website to download the corresponding version. It should be noted that you need to download the develop pack (development package) version, not the normal version. Otherwise useless.
2.4. Restart vscode.
VS code editor settings.
3.1. Enter the vscode editor and press ctrl + shift + P at the same time.
3.2. Enter in the pop-up input box: OmniSharp: select project.
3.3. Manually select the project file.
Normally, vscode cannot complete the error check because the version of omnisharp is wrong, omnishap may conflict with other versions of your vs code during the upgrade process, so you need to keep omnisharp to the latest version.
Solution:
4.1. Go to the console. Then click on the ouput bar and change the output type to ominisharp log. Windows version shortcut key: ctrl + shift + u.
4.2. Search for ominisharp in the setting.json file of vs code and change its path parameter to latest.
{
"[csharp]": {
"editor.defaultFormatter": "bilal-arikan.csharp-auto-formatter"
},
"omnisharp.path": "latest"
}
4.3. Restart vs code.
Hope it helps you.
I'm writing the code but the editor doesn't detect it. I looked in many places but could not solve the problem."Rigidbody" does not turn blue. Thank you in advance for your help.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class KarakterKontrol : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
Rigidbody fizik = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
}
}
I took a quick look at what "Diger dosyalar" meant.. which roughly translates to "Other Files", or in the English version of Visual Studio, Miscellaneous Files.
What that means is that your Visual Studio is not properly synced with Unity. You're seeing just a plain old C# file by itself, not a file that is associated with a Project.
The steps to rectify are usually:
Make sure "Visual Studio Editor" ( a.k.a. Visual Studio Tools for Unity) is installed in Package Manager.
Go to Edit > Preferences > External Tools and make sure that Visual Studio is set as your "External Script Editor".
Restart both Unity and Visual Studio, or even your whole machine to make sure.
9 times out of 10, that will resolve your issue.
I'm trying to handle in one time multiple projects in Visual Studio (SteamVR, Obi). Problem only occures in Visual Studio, in Unity Editor everything works fine.
My projects in Visual Studio 2019 look like this:
Now, I want to write code in main project script which will connect all projects. Code:
using Obi;
using UnityEngine;
using UnityEngine.Rendering;
using Valve.VR.InteractionSystem;
public class ObiURPSteamVR : MonoBehaviour
{
//1 - Obi - no problem in Unity, VS error in declaration
public ObiEmitter emitter;
//2 - URP Volume - working
public Volume URPVolume;
//3 - SteamVR - no problem in Unity, VS error in declaration AND in "using"
public Player steamVRPlayer;
}
My question is how to connect all projects, is it possible? And i will just add one more time, in Unity Editor everything is working, i can drag-drop SteamVR player and ObiEmitter, no errors are in console output. Thanks for every idea.
In Visual Studio, create an "empty solution". Add all your projects to this solution. When one project is referencing types from another project, right click on that project and "Add Reference".
So apparently its a bug in Unity 2019.3.12f version. Checked on 2019.4.01f and everything is working perfectly.
How do you go about "properly" setting up SFML for VS 2013? While a few places have given me a bit of information how to do it, nothing quite seems to work except one thing: SFML MS2012 Extension. However, I'd like to know how to do this from scratch for VS 2013 without the need of the extension.
Here is the current process I am using without the extension:
1) Open new project in VS 2013.
2) Add References to SFML libs(dlls): sfml-audio-2, afml-graphics-2 and sfml-windows-2.
3) Add extended libs via add-existing files: csfml-audio-2, csfml-graphics-2, csfml- windows-2, libsndfile-1 and openal32.
4) Create application.
Between the extension and doing everything myself, the noticeable difference is the GUID in the assembly information, yet if I attempt the previous steps and insert the GUID from the extension project into the new project, my attempt still fails to work even though the projects end up looking exactly the same. On top of which, where does the GUID come from and how do I go about getting it?
Secondary Question: Does XNA have all of the audio/graphic/window handling as SFML does? If so would it be better to switch to XNA than use SFML.Net?
Create a new C# project in Visual Studio 2012/2013/2015. It can be a Console Application or a Windows Forms Application. The only difference is, that a Windwos Forms Application generates a Form wich you can safely remove and the Console Applications shows a Console in the background.
Right-click your project in the Solution Explorer and click on Add Reference…
When the Reference Manager window appears, browse to the folder where you extracted the SFML.net archive and go to the lib folder. Select all the .dll files in the lib folder and Click on ‘OK’ in the Reference Manager to add them to your project.
Once the .dll files appear in the References section of your project, right-click your project again and click on Add > Existing Item… Navigate to the extlibs folder and add all the .dll files there (you may have to select .dll files as file filter in the Open dialog box).
Once these .dll files appear on your Solution Explorer, right-click on them and select Properties (or press Alt-Enter). In the Copy to Output Directory property, set it to Copy if newer.
SFML.net is now set-up for your project. To test it you can run this example code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using SFML;
using SFML.Graphics;
using SFML.Window;
namespace SFML_Test {
static class Program {
static void OnClose(object sender, EventArgs e) {
// Close the window when OnClose event is received
RenderWindow window = (RenderWindow)sender;
window.Close();
}
static void Main() {
// Create the main window
RenderWindow app = new RenderWindow(new VideoMode(800, 600), "SFML Works!");
app.Closed += new EventHandler(OnClose);
Color windowColor = new Color(0, 192, 255);
// Start the game loop
while (app.IsOpen()) {
// Process events
app.DispatchEvents();
// Clear screen
app.Clear(windowColor);
// Update the window
app.Display();
} //End game loop
} //End Main()
} //End Program
}
It should output this:
I have set up my SFML.Net projects in Visual Studio 2013 and 2015 through this tutorial. I used some of the text from it for this answer.
I am working on a car driver game in Unity. I was attempting to make some touch screen buttons and adding a C# script for testing mouse and touch input, but I get the console error message
"Assets/Standard Assets/MouseButton.cs(4,28): error CS0246: The type
or namespace name `MonoBehavior' could not be found. Are you missing a using directive or an assembly reference?"
Script listed below:
using UnityEngine;
using System.Collections;
public class MouseButton : MonoBehavior {
void OnMouseDown() {
Debug.Log("The Mouse is down on " + this.name);
}
void OnMouseUp()
{
Debug.Log("The Mouse is up on " + this.name);
}
}
Small typo, but it happened to me too, so I can relate.
It's MonoBehaviour, as you would say in British English, not MonoBehavior.
https://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.html
For me on Windows 10, Visual Studio 2019, and Unity 2020LTS was working:
Check that is actually "MonoBehaviour" and not "MonoBehavior". Or an individual script behavior. If you open a second script MonoBehavior is not marked as red.
If the problem subsists in all scripts, then make a backup (just in case), and In Project right-click Asset and "Reimport All".
If that was not working, and the issue persists, select Edit > Preference... > External Tools > External Script Editor > and switch "Visual Studio.." to "Open by file extension" or vice-versa. Just switching was working. Attention: "Open by file extension" will work without auto-completion.
If you select "Open by file extension" auto-completion will not work. You can try "Visual Studio [version number]". Then go to Package Manager > Packages: In Project > Visual Studio Editor and upgrade to the latest verified version. Remove "Visual Studio Code Editor". And lastly "Reimport All".