I’ve learned a lot on how to code using C# in Unity but when I watched C# on YouTube, it is different from what i have learned in Unity using C#. To those of you who code in Unity, do you also find C# on YouTube different?
Unity uses mono which has some quirks, especially if you are on the old Mono 2 version. But the principles are the same
There’s 3 parts to the whole thing.
The language.
The runtime.
The Unity API.
Also, there are versions to all.
Unity uses the C# language. It is the language as it is defined (for the prescribed version you use). There’s no difference in the language.
Unity uses the Mono runtime instead of the .Net runtime. As a result there are some oddities/quirks with it. It means performance and other stuff may vary slightly to .Net. This also dictates the core library (system namespace and what not), the Mono library is designed to mimic the .Net library pretty dang closely. It names everything pretty much the same.
Unity has its own API that offers up features not in vanilla mono/.net. Things like MonoBehaviour, Coroutines, Messages (the way Update works for instance), GameObjects, all of that stuff is framework dependent to Unity itself and isn’t directly applicable to non-unity stuff.
…
The other side of the coin is versions.
Unity by default uses a very old version of Mono, and a very early version of C#. It’s close to the equivalent of .Net 3.5 and C# 3.0.
To give you some comparison, .Net is currently on version 4.7.2/Core, and the most modern C# is 7.0
Unity of course allows you to put it your game into .Net 4.6 equivalent mode. But this is a new feature of Unity.
…
What you find on Youtube for C# not related to Unity may stem from a variety of these things.
They’re using features of a newer version of the language. They’re using features of a newer version of the runtime. Or they’re doing stuff not related to Unity and you don’t find it familiar because you’re used to the Unity API and the “Unity Way” of doing things.
There are indeed a lot of differences on how we use the language in a standard .net forms/wpf/etc way and in Unity.
You don’t necessarily have to limit yourself to see it by youtube, just start a new c# forms in visual studio and see how it works. You might learn a bit more of how powerful C# is.
The language is the same. There is a lot of Unity specific stuff though that has you writing your code differently than if you were building a standalone application outside of Unity. The typical Unity way of doing things puts Unity itself at the center of your game, and you basically hang your C# scripts off of GameObjects like leaves on a tree, and make use of regular calls to methods like Update to progress the state of your game in all the independent scripts.
A typical standalone application written in C# though would obviously have your C# code at the center, and have you branch out from there. You’d only have a concept similar to regular Update calls if you implemented such a system yourself from scratch, but your average non-game application would be unlikely to need something like that.
Use package manager to access the latest C# (it’ll be kept up to date according to Unity). Will soon be default.