# C# Scripting Tutorials

for the Unity Engine

- Unity, C#, logic, mathematics.
- Insight, control, results.

These tutorials teach you about C# scripting for Unity. The tutorials build on one another, introducing new programming concepts, math, algorithms, and Unity features. They will be useful to you, whether you're brand new to scripting or an experienced developer.

The tutorials are all written, not videos. They are enhanced with plenty of screenshots and diagrams. Recent tutorials also contain short animations.

The tutorials are written by me, Jasper Flick from Catlike Coding.

## Tutorials

### Basics

These tutorials provide an introduction to working with C# in Unity.

# Game Objects and Scripts

Build a clock with simple objects, then animate it with a custom script.

# Building a Graph

Instantiate and control a line of objects to visualize a mathematical function.

# Mathematical Surfaces

Upgrade the line graph to a grid, then to unrestrained surfaces constructed with multiple sine waves.

# Constructing a Fractal

Recursively add chilren to a game object, add some randomization, and you get your own 3D fractal. Use a coroutine to see it grow.

# Frames Per Second

Design a test scene to tank your FPS, then measure it with your own counter.

# Object Pools

Create a fountain of stuff, then feed it with your own object pools.

# Curves and Splines

Start with a line segment, then work your way up to quadratic Beziér curves and splines. All fully editable in the scene view.

### Mesh Basics

An introduction to procedural meshes. From a simple grid to deformable balls.

# Procedural Grid

Create a simple grid of vertices and triangles.

# Rounded Cube

Use your knowledge of grids to build a rounded cube.

# Cube Sphere

Turn a cube mesh into a sphere, then use mathematical reasoning to improve it.

# Mesh Deformation

Take any mesh and turn it into a deformable stress ball.

### Rendering

A series about understanding Unity's rendering pipeline. How a mesh turns into pixels that look like real objects.

# Matrices

Use matrices to transform space.

# Shader Fundamentals

Write your first shader, from scratch.

# Combining Textures

Mix multiple textures to add details and variety.

# The First Light

Go from a single dot product all the way to physically-based shading.

# Multiple Lights

Support complex lighting with pixel, vertex, and spherical harmonics lights.

# Bumpiness

Make surfaces look bumpy, by using height fields, normal maps, and tangent space.

# Shadows

Make objects both cast and receive shadows.

# Reflections

Use reflection probes to turn surfaces into mirrors.

# Complex Materials

Create a custom shader GUI and support metallic, smoothness, and emission maps.

# More Complexity

Use occlusion maps and details masks. Also support multi-material editing.

# Transparency

Make parts of your surfaces disappear.

# Semitransparent Shadows

Support shadows with holes in them.

# Deferred Shading

Add support for the deferred rendering path.

# Fog

Include fog in forward shading, and use an image effect for deferred fog.

# Deferred Lights

Render deferred lights after filling the G-buffers.

# Static Lighting

Baking lighting for static geometry into lightmaps.

# Mixed Lighting

Combine baked and realtime lighting in various ways.

# Realtime GI, Probe Volumes, LOD Groups

Support dynamic global illuminates, use probe volumes for large objects, and adjust what's rendered based on view size.

# GPU Instancing

Render many similar objects in a few batches.

# Parallax

Add a convincing illusion of depth to surfaces.

### Advanced Rendering

These are tutorials covering more complex or specialized rendering techniques, going beyond Unity's standard shaders. They build on the work done in the Rendering series.

# Flat and Wireframe Shading

Use screen-space derivative instructions and a custom geometry shader stage to apply flat shading and a wireframe effect to any mesh.

# Tessellation

Subdivide triangles into smaller ones with a custom hull and domain shader.

# Surface Displacement

Use tessellation combined with vertex displacement to turn a flat plane into something interesting.

### Hex Map

A series about hexagon maps. Lots of strategy games use them.

# Creating a Hexagonal Grid

Generate a simple hex grid and support in-game editing of cell colors.

# Blending Cell Colors

Connect cell with each other and blend their colors.

# Elevation and Terraces

Give cells different elevation levels and connect them with terraces.

# Irregularity

Perturb cell edges and elevations to produce a more natural map.

# Larger Maps

Make large maps possible, and provide the tools to edit them.

# Rivers

Draw rivers across the terrain, and animate them.

# Roads

Add roads to the map, and make them play nice with rivers.

# Water

Create bodies of water at various elevations, and flow rivers in and out of them.

# Terrain Features

Add detail objects to the terrain to represent plants, farmland, and urban development.

# Walls

Segregate cells by placing walls along their edges.

# More Features

Support wall towers, bridges, and larger features.

# Saving and Loading

Write maps to a file, and read them back.

# Managing Maps

Make it possible to work with multiple maps of various sizes.

# Terrain Textures

Cover the terrain with textures.

# Distances

Find the shortest distances to a cell.

# Pathfinding

Search for the shortest path between two cells.

# Limited Movement

Split movement into turns and find paths as quickly as possible.

# Units

Add unit to the map and move them around.

# Animating Movement

Send units on a journey across the map.

# Fog of War

Distinguish between visible and invisible cells.

# Exploration

Only show parts of the map that have been explored.

# Advanced Vision

Base vision range on elevation and smoothly transition between hidden and visible cells.

# Generating Land

Lay the foundation for procedurally generated maps.

# Regions and Erosion

Segregate landmasses and apply erosion.

### Noise

Procedural noise is useful for lots of things. This series shows how to make your own value, Perlin, and simplex noise, including their derivatives.

# Noise

Create a procedural texture, then fill it with pseudorandom noise. Go from 1D to 3D, generating both Value and Perlin noise.

# Noise Derivatives

Create a procedural mesh, using noise to turn it into a terrain. Then compute analytical noise derivatives and create Curl noise.

# Simplex Noise

Discover how to create alternatives for Perlin and Value noise, based on a simplex grid.

### Marching Squares

A series about drawing and reconstructing shapes using a 2D grid. Why not Marching Cubes? Because the concepts are the same for both 2D and 3D, and dealing with two dimensions is already complex enough.

# Partitioning Space

Build an editable 2D voxel grid, then triangulate it with the Marching Squares algorithm.

# Sharing and Crossing

Add vertex sharing and flexible edge crossings to Marching Squares.

# Staying Sharp

Enhance Marching Squares with Hermite data, then reconstruct sharp features and resolve ambiguous cases.

# Erecting Walls

Refactor Marching Squares a bit, then add walls to give it some depth.

# Being Colorful

Make Marching Squares more colorful by adding support for multiple materials.

### Games

Tutorials that can be considered small games.

# Swirly Pipe

Create a prototype racing game where you move through endlessly twisting pipes.

# Maze

Procedurally fill a rectangular area with a random walk. Add walls, doors, rooms, and other details. Then navigate the maze you have created.

### Older Tutorials

These tutorials are old. They work for Unity 4. I won't update them to Unity 5. They still have value, but you'll likely have to make adjustments yourself.

# Graphs

Visualize mathematical functions using particle systems, and even animate them. Show a 1D line, a 2D grid, and a small 3D voxel system.

# Runner

Create an endless runner game with different platform types and a power-up. Use physics, particle systems, managers, events, and queues.

# Octahedron Sphere

Create an approximation of a sphere by subdividing the faces of an octahedron. This tutorial was commissioned by Binpress.

# Custom Data

Create a custom data type for a colored point, then make it easier to edit by giving it a custom property drawer.

# Custom List

Build an alternative visualization for arrays and list. Then give it a few configuration options.

# Star

Using a list of colored points, create a simple star object by means of a dynamic mesh, which exists in edit mode and is editable in the scene view.

## Questions & Answers

Have a question? Here are a few common ones. Click or touch the questions to see the answers. You can also contact me in various ways.