One of the biggest differences between C# and Unity's framework is the GameObject
and Component
system in Unity. Unity API is component based.
There is a GameObject
and Component
which can be attached to a GameObject. When you create a GameObject, you can attach a component to it with the AddComponent
function. You can just assume that the component is your script/class.
In a normal C#, you can create new class instance with the new
keyword:
ClassName clsVar = new ClassName();
With Unity Framework, you create new Component and attach it to an Object with the AddComponent
function instead of the new
if it is a component:
ClassName clsVar = gameObject.AddComponent<ClassName>();
You can also destroy that GameObject or Component with the Destroy
.
Destroy(clsVar);
Another notable difference are constructors. It is not advised to use constructors in your scripts unless they do not inherit from MonoBehaviour
.
Those are the biggest notable differences. Everything else remains the-same. If you learn C# console(No WPF/Winform needed) and understand the syntax, you can learn and understand Unity API within couple of days.
Okay my simple question is will I be able to code in c# programming
and not relying on unity script or library in 2 years? WITHOUT having
to relearn some functions and libraries?
Yes, but you will have to re-write your app with another framework. First of all, C# is a programming language. Unity is a platform that provides C# API that runs on devices other than Windows such as Android, iOS and MacOS. There are other alternatives such as Xamarin which has its own API too. You can also use WPF and Winform but they are only made to work on Windows. They all have difference API for doing something like playing sound, showing object on the screen and networking and you just have to relearn them if you switch to another one.
If you are using standard C# API that does not involve playing audio, graphics, it should also work in Unity. For example, the Socket, Thread, IO API's should work in Unity without any hard-work.
As long as you understand the C# language syntax, you just need to study the API of these platforms such as being able to remember class and functions names and what they are used for. Finally, if you need to start learning C# with Unity, you can do that with Unity's official C# tutorial which uses Unity to teach basic C# programming.