unity-csharp-scripting
Fungsinya
Skill ini mengajari agent menulis skrip Unity C# yang jelas dan andal untuk perilaku game. Skill ini ditujukan untuk developer yang membuat gameplay di Unity 6.
Kapan dipakai
- βSaat Anda membuat atau memperbaiki skrip MonoBehaviour di Unity.
- βSaat skrip perlu menjalankan sesuatu berdasarkan timer atau selama beberapa frame.
- βSaat Anda ingin field muncul di Inspector Unity agar desainer dapat mengubahnya.
Link skill
https://github.com/gamedev-skills/awesome-gamedev-agent-skills/blob/main/skills/unity/unity-csharp-scripting/SKILL.mdSalin lalu tempelkan ke AI Anda (Claude, ChatGPT, atau Cursor) dan minta AI mengikuti instruksinya.
Cara pakai
Cara paling mudah: salin pesan ini dan tempelkan ke AI Anda. AI akan membaca skill dan mengikuti instruksinya.
Pesan siap tempel
Untuk Claude Code, Codex, atau Cursor: jalankan di folder proyek, lalu skill langsung terpasang.
Unduh SKILL.md lalu taruh di folder skill agen Anda.
Contoh permintaan ke AI
βTulis skrip Unity yang membuka pintu saya ketika pemain berdiri di depannya selama dua detik.β
5 skill baru setiap minggu. 1 menit baca.
Cara kerjanya
Skill menjelaskan fungsi Unity mana yang dipakai untuk setiap tugas, cara menyimpan referensi komponen sekali alih-alih mencarinya setiap frame, serta cara mengekspos pengaturan dan menjalankan logika berwaktu dengan coroutine.
Konten teknis (SKILL.md asli)
Teks asli dari pembuat, dalam bahasa Inggris, langsung dari GitHub.
Unity C# Scripting (MonoBehaviour)
Write correct, idiomatic gameplay scripts in Unity 6. Get the lifecycle, component access, serialization, and coroutines right so behaviour is deterministic and the Inspector stays useful. Targets Unity 6.3 LTS (6000.3), C# / .NET Standard 2.1.
When to use
- Use when authoring or fixing a
MonoBehaviour: choosing the right lifecycle callback, reading/caching components, exposing fields to the Inspector, or running timed logic with coroutines. - Use when the project has
*.csfiles, anAssembly-CSharpor*.asmdef, and aProjectSettings/folder.
When not to use: moving rigidbodies / collision response β unity-physics; reading
player input β unity-input-system; shared data assets / config β unity-scriptableobjects;
Animator parameters β unity-animation. This skill owns the script lifecycle and C#
plumbing, not those subsystems.
Core workflow
- Pick the callback by purpose, not habit.
Awake(cache references, runs once on load),OnEnable(subscribe to events),Start(init that depends on other objects'Awake),Update(per-frame logic/input polling),FixedUpdate(physics),LateUpdate(camera follow after movement),OnDisable/OnDestroy(unsubscribe/cleanup). - Cache component lookups in
Awakeβ never callGetComponentevery frame. - Expose tunables with
[SerializeField] private, not public fields, so other code can't mutate them but designers can edit them in the Inspector. - Scale per-frame values by
Time.deltaTimeinUpdate(andTime.fixedDeltaTimesemantics are automatic inFixedUpdate). - Use coroutines for time-sequenced logic (delays, tweens, "do X then wait then Y");
start them with
StartCoroutineand stop them deterministically. - Verify in Play mode: check the Console for null-reference exceptions, confirm values
in the Inspector update as expected, and watch the Profiler if
Updateis hot. - Check
.metafiles before you finish. When you create, move, rename or delete scripts or assets outside the Editor, always move a file together with its.meta(a new.metameans a new GUID and broken references). Then runpython scripts/check_unity_project.py <project-dir>(--jsonfor machine-readable output), fix everyERROR(duplicate or malformed GUIDs, files moved without their.meta, missing script references) and re-run until it exits 0. A missing.metaon a brand-new file is only a warning; Unity creates it on the next import. Run the script path relative to this skill directory, or resolve the installed skill path first. It needs Python 3.10+ and nothing else, reads only text-serialized assets, and does not replace opening the project in Unity.
Patterns
1. Lifecycle + cached components (the canonical skeleton)
using UnityEngine;
[RequireComponent(typeof(Rigidbody))] // auto-adds the dependency, prevents null refs
public class PlayerController : MonoBehaviour
{
[SerializeField] private float moveSpeed = 6f; // editable in Inspector, private in code
private Rigidbody _rb; // cached, not fetched per frame
private void Awake() => _rb = GetComponent<Rigidbody>(); // cache once on load
private void Update()
{
// Per-frame, non-physics work. Scale by deltaTime so it is frame-rate independent.
transform.Rotate(0f, 90f * Time.deltaTime, 0f);
}
private void FixedUpdate()
{
// Physics work belongs here (fixed timestep). See the unity-physics skill.
_rb.MovePosition(_rb.position + transform.forward * moveSpeed * Time.fixedDeltaTime);
}
}
2. Safe component access with TryGetComponent
// Avoids allocating a null and is clearer than GetComponent + null check.
if (other.TryGetComponent<Health>(out var health))
health.Apply(-10);
3. Serialization that shows up correctly in the Inspector
[SerializeField, Range(0f, 1f)] private float volume = 0.8f; // slider
[SerializeField] private string playerName = "Hero"; // private but serialized
[System.Serializable] // REQUIRED for a plain class to serialize/show
public class Stats { public int hp = 100; public int mana = 50; }
[SerializeField] private Stats stats = new(); // nested struct-like data in the Inspector
4. Coroutines for time-sequenced logic
private voi
Pertanyaan umum
Apa itu MonoBehaviour?
MonoBehaviour adalah jenis skrip dasar yang Anda pasang ke objek dalam scene Unity.
Haruskah saya mencari komponen setiap frame?
Tidak. Skill menyebutkan untuk mencari komponen sekali dan menyimpannya, biasanya saat objek aktif.
Apakah ini mencakup fisika atau input?
Tidak. Keduanya dicakup oleh skill Unity yang terpisah.
Detail
Deskripsi asli dari pembuat
Write Unity 6.3 LTS C# gameplay scripts: the MonoBehaviour lifecycle (Awake/OnEnable/Start/Update/FixedUpdate/LateUpdate), GameObject and component access, coroutines, and Inspector serialization. Use when creating or editing .cs scripts in a Unity project, or when the user mentions MonoBehaviour, Start/Update, GetComponent, SerializeField, coroutines, or "Unity script".
Popularitas
- Bintang GitHub
- 6.6k
- Peringkat
- #13846
- Lisensi
- Apache-2.0
- Diperbarui
- 28/10/2026
Komentar
- β¦
Skill lain dari repositori ini
router
6.6kMembantu agent Anda memilih skill pengembangan game yang tepat untuk setiap permintaan dengan mendeteksi engine Anda dan jenis tugas yang Anda perlukan.
ai-behavior-trees-utility-ai
6.6kMembantu agent Anda membangun behavior tree dan sistem utility AI untuk musuh dan karakter game yang memilih aksi berdasarkan prioritas dan skor.
audio-design
6.6kMengajari agent Anda cara mixing audio game: bus, volume dalam desibel, ducking di bawah dialog, musik adaptif, dan variasi efek suara.
camera-systems
6.6kMembantu agent Anda membangun kamera game yang mengikuti dengan halus, tetap berada di dalam level, dan dapat mengorbit atau melihat sekeliling dalam 3D.
Skill serupa
diffs
394kMemungkinkan agent Anda menghasilkan diff perubahan yang nyata dan dapat dibagikan sebagai tautan viewer atau file gambar, bukan ringkasan yang ditulis manual.
coding-agent
394kMembantu agent Anda menyerahkan pekerjaan pemrograman besar ke Codex, Claude Code, atau OpenCode di latar belakang, lalu memeriksa kemajuannya.
gh-issues
394kMembantu agent Anda menemukan issue GitHub, memilih yang dikerjakan, dan membuka pull request perbaikan, termasuk tindak lanjut komentar tinjauan.