How to count the scripts in a Unity project
Unity doesn't show how many scripts a project has or how many lines of code they add up to. Here are three quick ways to find out, from a search box to a reusable menu item.
1. Search the Project window
In the Project window's search box, type t:MonoScript. Unity lists every script in the project, including ones in packages. To see only your own, switch the search scope from "All" to "In Assets".
This is quick for browsing, but it doesn't give you a total or a line count.
2. Add a "Count Scripts" menu item
Put this script in a folder called Editor inside Assets. It adds Tools > Count Scripts, which logs the number of scripts, the total lines and the five longest files.
using System.IO;
using System.Linq;
using UnityEditor;
using UnityEngine;
public static class CountScripts {
[MenuItem("Tools/Count Scripts")]
public static void Count() {
var scripts = Directory.GetFiles(Application.dataPath, "*.cs", SearchOption.AllDirectories)
.Select(path => new {
Name = Path.GetFileName(path),
Lines = File.ReadLines(path).Count(),
Bytes = new FileInfo(path).Length
})
.ToList();
Debug.Log($"{scripts.Count} scripts, {scripts.Sum(s => s.Lines):N0} lines, " +
$"{scripts.Sum(s => s.Bytes) / 1024f:F1} KB");
foreach (var s in scripts.OrderByDescending(s => s.Lines).Take(5)) {
Debug.Log($" {s.Name}: {s.Lines:N0} lines");
}
}
}
Application.dataPath is your Assets folder, so the count leaves out packages and Unity's own Library folder.
3. Count from the command line
Open a terminal in your project folder (the one that contains Assets).
Windows (PowerShell)
# Number of scripts
(Get-ChildItem -Path Assets -Recurse -Filter *.cs).Count
# Total lines of code
Get-ChildItem -Path Assets -Recurse -Filter *.cs | Get-Content | Measure-Object -Line
macOS and Linux (Terminal)
# Number of scripts
find Assets -name "*.cs" | wc -l
# Total lines of code
find Assets -name "*.cs" -exec cat {} + | wc -l