Learn C# for Unity — Beginners Guide to Unity
Arthur Ribeiro / Dejan Gajsek
C-sharp (C#) is a popular programming language developed by Microsoft in 2002. It has also been a main language for Unity game engine since 2005. Unity3D, being one of the two main obvious choices for AR/VR development (apart from Unreal Engine by Epic Games), requires for AR/VR learners to get a handle of it if they want to develop applications with some complexity (think physics, animations, to design patterns, shaders or even sound effects).
Chances are, you are excited to build applications for AR and VR, but are afraid of delving into a programming language. Anyone who have been building Unity games is already familiar with the C#. But to a non-technical person the script presents a steep learning curve. Don't worry - unity game engine becomes a lot easier to work with once you understand the language.
This guide is a shortcut or a refresher course of C# programming language.
Through C# you can create new components or extend existing ones, shaping how your game works, defining player interactions, enemy behaviors, moving objects around, and much more.
What is C#?
Inspired by its predecessors C and C++, C-sharp (C#) is a programming language developed by Microsoft, capable of a wide range of tasks, but most importantly, it's the programming language used by the game engine by Unity Technologies. Currently, Unity (v 2019.4) uses C# version 7.3.
Why Should you Learn to Code C#?
Unity offers many features out of the box, and you can get even more from the asset store or similar places. However, they are all designed to be generic and you will often stumble into something that needs to be a bit different, especially when adding that unique pizzazz to your game.
Understanding C# will broaden your horizons and give you the ability to create custom and complex features, unlocking the full potential of the Unity game development 3D engine. Even if you don't plan to become a programmer, it is important to understand what can be done with coding for better communication with your team.
Unity is a cross-platform game engine which means your applications made with Unity can live on multiple platforms - from gaming pc desktops, consoles (PlayStation, Xbox), mobile (android and iOS) and of course, AR/VR platforms (steamVR, Oculus Play Store, Circuit Steam Platform, ...).
C# shares many features and concepts with other programming languages, which makes it a good starting point for learning how to program. Also, learning while making games is definitely faster with better retention, and let’s be honest… way cooler.
Important Aspects When Learning C#
C# is especially useful in XR development because this media is still in its infancy. Out of the box features are still under development, as people haven’t found the best solution for XR problems, nor the best implementations of the solutions we currently have.
Even though you can get away with "no-code" solutions such as XR Interaction Toolkit API (introduced in early 2020) where you can create interactions without writing scripts, this would only be a temporary solution to the problem.
Before jumping in with all the vigor and excitement, check yourself. Programming may appear difficult, complex, and at the times, even tedious. This goes double for someone who is coming from a creative field.
To those I say this:
- Be patient — you are learning a life skill that is going to stay with you forever. The start is always the hardest and you're going to feel like you're improving at a glacial speed. Keep at it.
- Build small projects — just typing in the sample code is as interesting as watching the paint dry. To make it more appealing, put the code that you've learn into practice. It makes all the difference when your avatar in VR moves the way you wanted to. These projects don't need to be AR/VR related. There are hundreds of mini tutorials where you can build simple 2d games. Unity3D was primarily build as a development engine for 3d games first!
- Think of an end goal — all XR developers starts learning C# (or C++ for Unreal Engine) to build the idea they have in mind. Getting familiar with scripting is just the means to get to that goal. When you're learning C# think of the great animations you will be able to implement in your VR game, add realistic physics to your gameobjects, or add amazing effects to your design.
How Long Does it Take to Learn C# for Unity 3D?
Learning how to program is a challenge, though a rewarding one. After 6 months of dedicating at least 1 hour per day, many people find that they can create small XR projects with confidence. The first 6 months are all about laying a strong foundation to build upon for the future.
By grasping the skill of C# programming you will not only be comfortable getting into the AR/VR development but you will also be able to build your own 2D (or 3D) games for different platforms. More into game design? No problem - if you're using Unity, you're going to need C#.
How to Learn C# for Unity
Every person has their preferred way of learning. You can go straight to the source and learn on the Microsoft's C# documentation page. But you want something more interactive on this topic, don't you?
Here are our favorite sources:
Instructor Guided Classes
Having an instructor guide you through the course content, and being available to answer eventual questions can be a really good approach to learning. C# Scripting Fundamentals in Unity is a great example.
If you are feeling old school or just prefer the physicality of books, there are plenty of good sources, like Head First C# by Andrew Stellman.
Pre-recorded Classes & Online Courses
Seeing someone programing step by step can really help clear some questions and avoid common mistakes. Unity has a series on C# programming if you want to check it out!
What about C# Certification?
There are certified courses and programs where you can earn a certificate for completion. We've found a C# Programming course from UC of San Diego and more relevant, C# Programming for Unity Game Development from University of Colorado.
Honestly, in my opinion the certifications aren't necessary unless your potential employer demands it. It's much more important that you have your portfolio of small projects you can show off than piece of paper or a badge. But if you have the money, go ahead.
Studying can get boring sometimes, so doing some small projects can really get you pumped up to keep going. There are plenty of workshops simple enough that you can follow without knowing any C#, but can get even more out of it if you do.
Check out some of the Circuit Stream's C# workshops on YouTube
Tutorials like these 🙂
For well structured and direct information on C# programming, tutorials are the best, get the core of what you need to get started, and pointers on how to develop further.
This guide serves as a fun way to get familiar with Unity script without prior programming experience.
Your C# Lesson Plan Series
In each chapter of this series, we tackle a C# fundamental topic, focusing on the programming language concepts and giving plenty XR focused examples and extra reading material. Think of it as weekly assignments that you can tackle when it's convenient for you.
Data types are a way to tell the computer what is a piece of data and what can be done with it, like numbers and texts.
Our code constantly needs to make questions: is the player pressing the grip button? Is the power up ready to be used? And with those questions, decide how to proceed: the player should only grab an object if the grip button is pressed. This can be achieved through Programming Logic and Conditionals, which we will explore in this chapter.
In this chapter, we will demonstrate a way to reuse and organize our code, through methods, which simply put, is a set of instructions combined.
Oftentimes we need to deal with a large number of similar data or repeat a set of instructions multiple times. Arrays and Loops are the built-in solutions for that.
Classes are a way to define a custom data type, with more complex information and usages. Classes are a good way to make real-world abstractions, like a hand or a gun.
Inheritance and Interfaces introduce a way to reuse and structure code through multiple classes.
In this chapter we tie everything together, explaining how Unity leverages all these concepts in the engine, and walk you through a demo Unity project.
Where to next?
We will release a chapter of this tutorial per week, so keep your eyes peeled!
Meanwhile get your Unity and Visual Studio setup going, explore some sample projects and happy coding!
Download XR Development with Unity Course Syllabus