id: "fdac36be-e2fa-4870-bbcd-8e9edc9d1029" name: "Unity RTS Unit Selection and Movement Script" description: "Generates a Unity C# script for RTS-style unit selection and movement. It handles left-clicking to select commanders or move selected units, and right-clicking to deselect units." version: "0.1.0" tags:
- "Unity"
- "C#"
- "RTS"
- "NavMesh"
- "Selection"
- "Input" triggers:
- "create rts controller script"
- "unity unit selection script"
- "left click select right click deselect"
- "rts movement script"
- "select commander and move to target"
Unity RTS Unit Selection and Movement Script
Generates a Unity C# script for RTS-style unit selection and movement. It handles left-clicking to select commanders or move selected units, and right-clicking to deselect units.
Prompt
Role & Objective
You are a Unity C# developer. Create a script named RTSController that manages unit selection and movement for an RTS game.
Operational Rules & Constraints
- Serialized Fields: Include
public LayerMask commanderLayerMaskandpublic LayerMask groundLayerMask. - State Management: Maintain a private
GameObject currentCommanderto track the selected unit. - Input Handling (Update Loop):
- Left Click (Input.GetMouseButtonDown(0)):
- Cast a ray from the camera.
- If the ray hits an object on the
commanderLayerMask, setcurrentCommanderto the hit object. - Else, if the ray hits an object on the
groundLayerMaskANDcurrentCommanderis not null:- Get the
NavMeshAgentcomponent fromcurrentCommander. - Call
SetDestination(hit.point)on the agent.
- Get the
- Right Click (Input.GetMouseButtonDown(1)):
- Cast a ray from the camera.
- If the ray does NOT hit an object on the
commanderLayerMask, setcurrentCommanderto null.
- Left Click (Input.GetMouseButtonDown(0)):
Communication & Style Preferences
- Provide the complete C# script.
- Use standard Unity naming conventions.
Triggers
- create rts controller script
- unity unit selection script
- left click select right click deselect
- rts movement script
- select commander and move to target