๐ŸŽฏAuto Gun Target

Auto Gun Target

This component can be used to trigger extra events when being shot by an Auto Gun including spawning, playing, and pooling, hit particles or use the On Shot unity event to create more custom result on hit. Must be attached to a target's rigidbody to work properly

This component is not required to trigger the gun's On Hit event.

GameObject Hit Decal

  • Use Case: This variable holds a reference to the GameObject that represents the decal (like a mark or a bullet hole) to be instantiated when a shot hits a target. The hitDecal is visually displayed at the point of impact.

ParticleSystem Hit Particle;

  • Use Case: This variable is used to reference a Particle System that should be triggered when a shot hits a target. It's typically used to create visual effects like sparks, smoke, or fragments at the impact location to enhance visual feedback.

float Hit Decal Lifetime;

  • Use Case: This float value determines the lifetime of the hit decals. It specifies how long (in seconds) the decals should remain visible in the scene after being created. Once this time elapses, the decal is either destroyed or recycled (depending on implementation).

UnityGunHitEvent OnShotEvent;

  • Use Case: Invoked when a shot occurs, allowing other components or systems in the game (like score managers, sound effects, or game logic) to respond to the shooting event. The event passes along information about the gun that fired and the RaycastHit details.

Here is an example of a script that uses the AutoGunTarget events

public class AutoGunTargetHandler : MonoBehaviour {
    public AutoGunTarget autoGunTarget;

    private void OnEnable() {
        if (autoGunTarget != null) {
            autoGunTarget.OnShotEvent += HandleOnShotEvent;
        }
    }

    private void OnDisable() {
        if (autoGunTarget != null) {
            autoGunTarget.OnShotEvent -= HandleOnShotEvent;
        }
    }

    private void HandleOnShotEvent(AutoGun gun, RaycastHit hit) {
        // This function will be called when the OnShotEvent is invoked.
        // Currently, it's empty and can be filled with custom behavior.
    }
}

Last updated