Unity primarily uses C# for scripting, which is the language that most game developers use when building games in Unity. C# is used to write scripts that define the behavior of objects in the game world, manage scenes, control the user interface, and implement game logic.
Unity itself is built on a combination of C++ and C#, with the core engine written in highly optimized C++ for performance reasons. This provides the necessary speed for demanding tasks such as rendering graphics, physics calculations, and other core functions that occur behind the scenes.
Developers using Unity usually interact with the engine through its C# APIs. Here's an example of a simple C# script in Unity that would make an object move:
In this script,
MonoBehaviour is a base class from the Unity Engine namespace,
Update() is a method called once per frame, and
transform.position refers to the position of the game object to which this script is attached.
Even though developers cannot use C++ directly within Unity to script game behavior, they can write native plugins in C++ if they need to leverage certain platform-specific features or optimize specific parts of their game that require a higher performance level than what can be achieved with C# alone.