RoutePreview
Overview
Simple LineRenderer-based helper that previews a route while the player is selecting endpoints. It shows a short segment at the origin and, until snapped, updates the end to the current mouse raycast hit. Provides Snap, Unsnap, Show, and Hide utilities. fileciteturn13file0
Behavior
- Start() — gets
LineRendererfrom the same GameObject and disables it. - Show(origin) — enables both the component and the line, sets both positions to
(origin.x, origin.y, -0.1). - Update() — when not snapped, raycasts from
Camera.mainthroughInput.mousePositionand updates the end position to the hit point’s(x,y,-0.1)if any collider is hit. - Snap(target) — fixes the end position to
targetand setssnapped = true. - Unsnap() — allows the end to track the mouse again.
- Hide() — disables both the component and the line. fileciteturn13file0
Notes & Integration
- Ensure the scene has appropriate 3D colliders on the map plane for raycasts to hit.
- Cache the
LineRendereronce (e.g., inStart) and reuse it in other methods. - Uses
Camera.maineach frame; consider caching a reference for performance-sensitive scenes. fileciteturn13file0