본문으로 건너뛰기
Skillpedia
일반 코딩6.6k · #13846

unity-csharp-scripting

하는 일

이 스킬은 에이전트가 게임 동작을 위한 명확하고 신뢰할 수 있는 Unity C# 스크립트를 작성하도록 가르칩니다. Unity 6에서 게임플레이를 만드는 개발자를 위한 스킬입니다.

사용하는 경우

  • ✓Unity에서 MonoBehaviour 스크립트를 만들거나 고칠 때.
  • ✓타이머로 또는 여러 프레임에 걸쳐 무언가를 실행해야 하는 스크립트가 필요할 때.
  • ✓디자이너가 바꿀 수 있도록 필드가 Unity 인스펙터에 보이기를 원할 때.

스킬 링크

https://github.com/gamedev-skills/awesome-gamedev-agent-skills/blob/main/skills/unity/unity-csharp-scripting/SKILL.md

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/gamedev-skills/awesome-gamedev-agent-skills/blob/main/skills/unity/unity-csharp-scripting/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“플레이어가 문 앞에 2초 동안 서 있으면 문이 열리는 Unity 스크립트를 작성해 주세요.”

매주 새 스킬 5개. 읽는 데 1분.

작동 방식

각 작업에 어떤 Unity 함수를 쓸지 설명하고, 매 프레임 검색하지 않도록 컴포넌트 참조를 한 번 저장하는 방법, 설정을 노출하고 코루틴으로 시간 기반 로직을 실행하는 방법을 보여 줍니다.

기술 내용 (원본 SKILL.md)

작성자의 영어 원문을 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 *.cs files, an Assembly-CSharp or *.asmdef, and a ProjectSettings/ 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

  1. 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).
  2. Cache component lookups in Awake — never call GetComponent every frame.
  3. Expose tunables with [SerializeField] private, not public fields, so other code can't mutate them but designers can edit them in the Inspector.
  4. Scale per-frame values by Time.deltaTime in Update (and Time.fixedDeltaTime semantics are automatic in FixedUpdate).
  5. Use coroutines for time-sequenced logic (delays, tweens, "do X then wait then Y"); start them with StartCoroutine and stop them deterministically.
  6. Verify in Play mode: check the Console for null-reference exceptions, confirm values in the Inspector update as expected, and watch the Profiler if Update is hot.
  7. Check .meta files 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 .meta means a new GUID and broken references). Then run python scripts/check_unity_project.py <project-dir> (--json for machine-readable output), fix every ERROR (duplicate or malformed GUIDs, files moved without their .meta, missing script references) and re-run until it exits 0. A missing .meta on 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
자주 묻는 질문

MonoBehaviour란 무엇인가요?

MonoBehaviour는 Unity 씬의 객체에 붙이는 기본 스크립트 타입입니다.

매 프레임 컴포넌트를 찾아야 하나요?

아니요. 이 스킬은 컴포넌트를 한 번만 찾아 저장하라고 말하며, 보통 객체가 활성화될 때 합니다.

물리나 입력도 다루나요?

아니요. 그것들은 별도의 Unity 스킬에서 다룹니다.

상세 정보

작성자의 원본 설명

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".

repo: gamedev-skills/awesome-gamedev-agent-skills

인기도

GitHub 스타
6.6k
순위
#13846
라이선스
Apache-2.0
업데이트
2026. 10. 28.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬