ProjectileAmmo

The ProjectileAmmo script represents a physical bullet with a Rigidbody. It moves through space and applies damage on collision.

Summary

This component:

  • Launches a projectile with velocity
  • Detects collisions and applies damage
  • Supports impact VFX and time-based destruction

Fields

FieldTypeDescription
_speedfloatSpeed of the projectile (default: 15).
_lifetimefloatHow long the projectile lives before self-destruction.
OnImpactUnityEvent<DamageData>Invoked when the projectile hits something.

Public Methods

MethodDescription
void SetSource(Transform spawnPoint)Sets the initial position and rotation of the projectile. Should be called before shooting.
void Shoot(int damage, GameObject owner)Launches the projectile in the forward direction with force.
void CreateImpact(GameObject prefab)Instantiates a VFX or decal prefab at the hit position.

Collision Behavior

  • On collision:
    • Creates a DamageData instance
    • Applies damage to Hitbox if found
    • Invokes OnImpact
    • Destroys the projectile

Note

Assign a Rigidbody and Collider to the projectile prefab.

Tip

Use pooling instead of Destroy() for optimization in high-fire-rate weapons.

See Also