Laser Guide

The LaserGuide script allows projectiles spawned by a ProjectileBarrel to dynamically follow a target using laser guidance. Players can toggle the laser system on and off at runtime, affecting all active projectiles.

Summary

This component:

  • Listens for LaserFollower projectiles
  • Assigns a dynamic target to them if laser is active
  • Allows toggling laser visibility and tracking behavior via input
  • Cleans up inactive projectiles on impact

Fields

FieldTypeDescription
targetTransformThe transform that projectiles will follow when laser is active.
barrelProjectileBarrelThe source barrel responsible for spawning the projectiles.
laserGameObjectThe laser pointer object shown/hidden on toggle.

Private Fields

FieldTypeDescription
controlsWeaponControlsInput mapping for toggling laser guidance.
laserActiveboolWhether laser guidance is currently enabled.
_activeProjectilesList<LaserFollower>List of currently active guided projectiles.

Methods

MethodDescription
Start()Subscribes to projectile spawn and input events.
ToggleLaser()Toggles laser tracking and updates all active projectiles accordingly.

Behavior

  • When a projectile with LaserFollower is spawned, its target is set based on laserActive.
  • If laser is disabled mid-flight, projectiles will stop tracking.
  • Projectiles are removed from the list once their OnImpact event triggers.
  • The system listens to ShootSecondary input to toggle.

Requirements

  • Projectiles must have a LaserFollower component.
  • ProjectileBarrel must invoke OnProjectileSpawned.

Use Case Examples

  • Laser-guided rockets
  • Smart missiles
  • Tactical pointers for enemy tracking

Tip

Use SetActive(false) on the laser GameObject to make the laser visually disappear when guidance is disabled.

Note

This component works best with LaserFollower-based projectiles that interpret target.

See Also