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. fileciteturn13file0

Behavior

  • Start() — gets LineRenderer from 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.main through Input.mousePosition and 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 target and sets snapped = true.
  • Unsnap() — allows the end to track the mouse again.
  • Hide() — disables both the component and the line. fileciteturn13file0

Notes & Integration

  • Ensure the scene has appropriate 3D colliders on the map plane for raycasts to hit.
  • Cache the LineRenderer once (e.g., in Start) and reuse it in other methods.
  • Uses Camera.main each frame; consider caching a reference for performance-sensitive scenes. fileciteturn13file0