Game Development Reference
In-Depth Information
Why C#?
When it comes to Unity scripting, an early question when making a new game
is which language to choose, because Unity offers a choice. The official choices
are C# or JavaScript. However, there's a debate about whether JavaScript should
more properly be named "JavaScript" or "UnityScript" due to the Unity-specific
adaptations made to the language. This point is not our concern here. The question is
which language should be chosen for your project. Now, it initially seems that as we
have a choice, we can actually choose all two languages and write some script files
in one language and other script files in another language, thus effectively mixing
up the languages. This is, of course, technically possible. Unity won't stop you from
doing this. However, it's a "bad" practice because it typically leads to confusion
as well as compilation conflicts; it's like trying to calculate distances in miles and
kilometers at the same time.
The recommended approach, instead, is to choose one of the three languages and
apply it consistently across your project as the authoritative language. This is a
slicker, more efficient workflow, but it means one language must be chosen at the
expense of others. This topic chooses C#. Why? First, it's not because C# is "better"
than the others. There is no absolute "better" or "worse" in my view. Each and every
language has its own merits and uses, and all the Unity languages are equally
serviceable for making games. The main reason is that C# is, perhaps, the most
widely used and supported Unity language, because it connects most readily to the
existing knowledge that most developers already have when they approach Unity.
Most Unity tutorials are written with C# in mind, as it has a strong presence in other
fields of application development. C# is historically tied to the .NET framework,
which is also used in Unity (known as Mono there), and C# most closely resembles
C++, which generally has a strong presence in game development. Further, by
learning C#, you're more likely to find that your skill set aligns with the current
demand for Unity programmers in the contemporary games industry. Therefore, I've
chosen C# to give this topic the widest appeal and one that connects to the extensive
body of external tutorials and literature. This allows you to more easily push your
knowledge even further after reading this topic.
Creating script files
If you need to define a logic or behavior for your game, then you'll need to write
a script. Scripting in Unity begins by creating a new script file, which is a standard
text file added to the project. This file defines a program that lists all the instructions
for Unity to follow. As mentioned, the instructions can be written in either C#,
JavaScript, or Boo; for this topic, the language will be C#. There are multiple ways
to create a script file in Unity.
 
Search WWH ::




Custom Search