Introducing Dragonfly Cloud! Learn More

Question: Does Unity Use C++ or C#?

Answer

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:

using UnityEngine; public class Mover : MonoBehaviour { void Update() { // Move the object upward in every frame transform.position += Vector3.up * Time.deltaTime; } }

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.

While C# is the primary scripting language in Unity, it is also possible to use other languages like UnityScript (a JavaScript-like language that is now deprecated) or Boo (also no longer widely supported). However, C# remains the recommended and most widely used language due to its robustness, performance, and extensive support both from Unity Technologies and the community.

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.

Was this content helpful?

White Paper

Free System Design on AWS E-Book

Download this early release of O'Reilly's latest cloud infrastructure e-book: System Design on AWS.

Free System Design on AWS E-Book

Start building today 

Dragonfly is fully compatible with the Redis ecosystem and requires no code changes to implement.