Update C# Script
unity_update_scriptReplaces an exact text block in a Unity script with new content, failing unless the old text occurs the specified number of times. Read the script first, then apply a focused diff.
Instructions
Replace an exact text block in a script (like a focused diff hunk). Fails unless old_text occurs exactly expected_occurrences times.
Workflow: unity_read_script first, copy old_text verbatim (whitespace matters), then call with new_text. Returns { path, replaced, total_lines }. Unity recompiles after the change — check console for errors.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | Project-relative script path, e.g. 'Assets/Scripts/PlayerController.cs' | |
| new_text | Yes | Replacement text (can be empty string to delete) | |
| old_text | Yes | Exact text block to replace (copy from unity_read_script) | |
| expected_occurrences | No | How many occurrences of old_text must exist (default 1; fails otherwise) |