10 / 13
DEVELOPER REFERENCE
10 / 13

Runtime C# API

Connect launcher and trajectory components to your gameplay code and lifecycle.

English guideSource: Unity 6000.3.13f1 · URP 17.3.0 · Windows Editor / DX12Web edition · 22 October 2026

The public components can be connected from your own gameplay code. The example below follows the supplied tutorial: assign a configured launcher, trajectory and target in the Inspector, and let this script own input.

Control a launcher and preview#

C#
using UnityEngine;
using ERAGANX.ProjectileToolkit;

public sealed class ExampleWeapon : MonoBehaviour
{
    public ProjectileLauncher launcher;
    public ProjectileTrajectory preview;
    public Transform target;

    void Start()
    {
        // This script owns input; disable automatic polling.
        launcher.SetInput(null);
        preview.SetSource(launcher); // may be on another object
        preview.SetPreviewDistance(30f);
        preview.SetPreviewDuration(3f);
        preview.SetPreviewBounceLimit(2);
        preview.SetAnimationSpeed(1.5f);
        preview.SetVisible(true);
    }

    void LateUpdate()
    {
        if (!target) return;
        launcher.aimPoint = target.position;
        // Automatic refresh can remain enabled for this setup.
    }

    // Call these from your UI or existing input system.
    public void Fire()
    {
        if (target) launcher.LaunchAt(target.position, 1f);
    }

    public void SelectMissile()
    {
        if (launcher.SelectProjectile("missile"))
            preview.Refresh();
    }
}

The loadout must contain a unique entry ID of missile. LaunchAt returns false when validation, cooldown or gameplay conditions block a shot. This example does not create or configure the referenced objects for you.

Launch a projectile without a launcher#

For a configured projectile controller, call Launch(origin, velocity). Pause, Resume, Stop, SetTarget and ResetProjectile support common runtime control. Do not call Tick unless you intentionally manage simulation manually.

Subscribe to events#

Projectile events include Launched, Collided, Bounced, Stopped, Expired and Despawned; the guide also lists Spawned, Surface Interacted and Target Changed. Use C# callbacks or Inspector UnityEvents and subscribe/unsubscribe with the owning component's lifecycle.

Contact events provide an impact point and normal for gameplay integration. A trajectory marker is only a predicted contact; it does not invoke projectile impact events.

Adapted from the supplied guide · PDF pages 10–11.View source guide ↗
Keep creating.ERAGAN STUDIO.

Search a topic, setting or method across all package guides.