If you know Unity, you already know most of Codetoy. Think of it as one MonoBehaviour with Update() and OnDrawGizmos(), running in the browser: no scenes, prefabs or inspector, and instant iteration.
It's not a Unity replacement. It's a place to prototype a mechanic in five minutes, explore some math, or share a runnable idea with a link, then take it back to Unity.
Which language?
C# will feel like home, and every snippet here works in it. Switch to AssemblyScript in the sidebar if you want to publish your prototype as a build or Discord Activity; the concepts are identical.
#The mental model
| Unity | Codetoy |
|---|---|
| GameObjects and components | Plain variables and classes in one file |
| Scene hierarchy | None. You draw everything yourself. |
| Renderer components draw for you | Immediate mode: you draw every frame |
| Camera clears the screen | You clear it (paint a background) |
| World units, Y up | Pixels, origin top-left, Y down (like UI) |
| Physics engine | Write your own (it's simple for 2D) |
#The game loop
void Update() {
transform.position += velocity * Time.deltaTime;
}export function update()Screen.OnUpdate()def update() runs once per frame like Update(), and deltaTime()Screen.DeltaTimedeltaTime() is Time.deltaTime. There's one loop for the whole program rather than one per component.
#Drawing instead of instantiating
In Unity you create objects once and the engine renders them. In Codetoy nothing exists unless you draw it this frame, which is closer to OnDrawGizmos() or immediate-mode GUI.
Instantiate(circlePrefab, position, Quaternion.identity);To have "many objects", keep a list and draw each item in a loop. See Spawning without GameObjects.
#Cheat sheet
| Unity | Codetoy |
|---|---|
Update() |
export function update()Screen.OnUpdate()def update() |
Time.deltaTime |
deltaTime()Screen.DeltaTimedeltaTime() |
Time.time |
elapsedTime()not in C#elapsedTime() |
Input.mousePosition |
input.mouseX()Input.MouseXmouseX(), input.mouseY()Input.MouseYmouseY() |
Input.GetMouseButton(0) |
input.isMouseDown()Input.IsMouseDown()isMouseDown() |
Input.GetMouseButtonDown(0) |
export function onMouseDown()Input.OnMouseDown()def mouseDown() |
Input.GetKey(KeyCode.A) |
input.isKeyDown()Input.IsKeyDown()isKeyDown() with "a" |
Input.GetKeyDown(KeyCode.Space) |
export function onKeyDown()Input.OnKeyDown()def keyDown() with " " |
Screen.width / Screen.height |
screen.width()Screen.Widthwidth() / screen.height()Screen.Heightheight() |
Debug.Log / LogWarning / LogError |
console.log()Console.Log()print() / console.warn()Console.Warn()not in Python / console.error()Console.Error()print(..., file=sys.stderr) |
Gizmos.DrawWireSphere |
noFill()Canvas.NoFill()noFill() + circle()Canvas.Circle()circle() |
Mathf.Sin, Mathf.Atan2 |
Math.sin()Math.Sin()math.sin(), Math.atan2()Math.Atan2()math.atan2() |
Random.value |
Math.random()Random.Shared.NextDouble()random.random() |
#Input: polling and events
if (Input.GetKey(KeyCode.W)) y += speed * Time.deltaTime;
if (Input.GetKeyDown(KeyCode.Space)) Jump();Keys use browser names ("a", "ArrowUp", " "), not KeyCode. See the Input API.
#State without components
There's no inspector or serialization. Treat the top of your file like a component's fields:
Classes, structs, records, LINQ and generics all work. With top-level statements, declare your variables above any type declarations. See Language Notes.
#Spawning without GameObjects
void OnMouseDown() { Instantiate(bulletPrefab, transform.position, transform.rotation); }#Debugging
console.log()Console.Log()print(), console.warn()Console.Warn()not in Python and console.error()Console.Error()print(..., file=sys.stderr) print to the console under the editor, like Debug.Log. For per-frame values, a debug overlay drawn with text()Canvas.Text()text() is easier to read than a flood of logs:
#Codetoy or Unity?
Reach for Codetoy to: prototype a mechanic in minutes, visualize vectors and easing, teach a concept with something runnable, or share an idea as a link.
Move to Unity when you need: 3D, physics, an asset pipeline, animation tools, multiple scenes, or console and mobile builds.
Ready for a bigger example? Catch the stars is a complete mini-game in every language.