Unity C# Trainer

A Game Designed to Teach Beginners C# in a quick interactive way using the Roslyn Compiler.

About The Project



The features are the following:

Development

1. Using Roslyn Inside Unity

The Unity C# Trainer uses the Roslyn compiler to dynamically compile user-written code in real time. This allows beginners to learn C# interactively while seeing their scripts affect objects inside the scene.

Roslyn & Editor Imports


                        

2. Compiling User Code

When the player clicks Compile, their script is parsed into a syntax tree and passed into a Roslyn compilation pipeline. Any previous runtime script instances are safely disposed to avoid memory leaks.

Compile & Cleanup


                        

3. Building the Runtime Assembly

Unity does not allow runtime compilation natively, so the game uses Roslyn to generate an in-memory DLL containing the player’s script. All currently loaded assemblies are included as references so the script can access Unity APIs safely.

Assembly Builder


                        

4. Detecting the User’s Class

Once the in-memory DLL is created, the trainer searches for the first class that extends MonoBehaviour. This becomes the script that will run inside the game world.

Detecting MonoBehaviour


                        

5. Final Challenge Player Spawn

For the final challenge of the trainer, the game spawns a fully interactable character. The user’s compiled script is attached as its controller, teaching how real game logic drives gameplay.

Player Spawn Logic


                        

6. Runtime Update Invocation

If the user writes an Update() method, the trainer invokes it manually, effectively simulating how Unity’s real MonoBehaviour lifecycle works.

Runtime Update Loop


                        

7. Script Injection & Loading

The trainer supports loading scripts from external files, and injecting template code directly into the editor to guide beginners through challenges.

Inject & Load Scripts


                        

Full Code Available on Request

Download Project

Still in Active Development, Visit the Itch Page Below


Visit Itch Page