Pass ForgeDocs Product page

Scripting

Gameplay HUD

Damage numbers

PassForgeDamageNumbers.Spawn over an object adds quick hits up; at a point, numbers never add up. PassForgeDamageNumbers.SpawnText shows a word.

using PassForge.Effects;
using UnityEngine;

public static class DamagePopups
{
    // Over an enemy, quick hits add up into one number; criticals pop on their own.
    public static void Hit(Transform enemy, float damage, bool critical)
    {
        PassForgeDamageNumbers.Spawn(enemy, damage, critical ? DamageNumberKind.Critical : DamageNumberKind.Damage);
    }

    public static void Heal(Transform player, float amount)
    {
        PassForgeDamageNumbers.Spawn(player, amount, DamageNumberKind.Heal);
    }

    // "+10 XP" in gold at a point.
    public static void Loot(Vector3 chest, float xp)
    {
        PassForgeDamageNumbers.Spawn(chest, xp, DamageNumberKind.Gain, "XP");
    }

    // A color of its own, such as poison green.
    public static void Poison(Transform enemy, float damage, Color color)
    {
        PassForgeDamageNumbers.Spawn(enemy, damage, DamageNumberKind.Damage, color);
    }

    // Up to 12 characters: letters, digits and + - . , % ! /
    public static void Miss(Transform enemy) => PassForgeDamageNumbers.SpawnText(enemy, "MISS");
}

Which side a hit came from

PassForgeDamageIndicator.Show marks the side of the screen a hit came from. Given the attacker's Transform, it follows the attacker as the player turns.

using PassForge.Effects;
using UnityEngine;

// Shows the player which side a hit came from, around the middle of the screen.
public static class HitDirection
{
    // Follows the attacker as the player turns.
    public static void HitBy(Transform attacker) => PassForgeDamageIndicator.Show(attacker);

    // From a point, such as an explosion: stronger, for longer.
    public static void HitFrom(Vector3 explosion) => PassForgeDamageIndicator.Show(explosion, 1.5f, 2f);
}

Lead the player to an objective

SetDestination points the player's route at an object or a point, ShowTo leads somewhere else for a while, and ClearDestination hides it.

using PassForge.Effects;
using UnityEngine;

// Leads the player's route from one objective to the next.
public class ObjectiveRoute : MonoBehaviour
{
    [SerializeField] Transform[] m_Objectives;

    PassForgeRoute m_Route;
    int m_Next;

    void Start()
    {
        m_Route = PassForgeRoute.current;   // one route shows at a time: the one enabled last
        ShowNext();
    }

    public void ObjectiveDone()
    {
        m_Next++;
        ShowNext();
    }

    // An ally calls for help: the way to them for 20 seconds, then back to the objective.
    public void HelpAlly(Transform ally) => m_Route.ShowTo(ally, 20f);

    // Meters left along the route, for a label of your own. Text allocates, so update it a few times a second.
    public int metersLeft => m_Route != null ? Mathf.RoundToInt(m_Route.remainingDistance) : 0;

    void ShowNext()
    {
        if (m_Route == null)
            return;

        if (m_Next < m_Objectives.Length)
            m_Route.SetDestination(m_Objectives[m_Next]);
        else
            m_Route.ClearDestination();
    }
}

Warn of an attack on the ground

A Ground Marker fills up over the seconds you give StartFilling, then raises onFilled.

using PassForge.Effects;
using UnityEngine;
using UnityEngine.Events;

// An enemy's slam, warned of by a ground marker that fills up under the player first.
public class SlamAttack : MonoBehaviour
{
    [SerializeField] PassForgeGroundMarker m_Warning;   // a separate object, so it stays where the player stood
    [SerializeField] float m_WarningSeconds = 1.2f;
    [SerializeField] Transform m_Player;
    [SerializeField] UnityEvent m_PlayerHit;

    void OnEnable() => m_Warning.onFilled.AddListener(Slam);
    void OnDisable() => m_Warning.onFilled.RemoveListener(Slam);

    public void Telegraph()
    {
        if (m_Warning.isFilling)
            return;

        m_Warning.transform.position = m_Player.position;
        m_Warning.StartFilling(m_WarningSeconds);   // a moment in the marker's When Full plays the slam itself
    }

    // Such as when the enemy dies: a warning on the ground goes with it.
    public void Cancel() => m_Warning.StopFilling();

    void Slam()
    {
        var offset = m_Player.position - m_Warning.transform.position;
        offset.y = 0f;

        if (offset.magnitude <= m_Warning.radius)
            m_PlayerHit.Invoke();
    }
}

Radar and compass pings

PassForgePings.Ping shows a ping on every Fog of War Radar and Compass Bar. With revealEnemies, enemies within its radius show on the radars even out of sight.

using PassForge.Effects;
using UnityEngine;

// Pings on every Fog of War Radar and Compass Bar.
public static class RadarPings
{
    // A shot gives the shooter away. Close pings merge, so a weapon can call it on every shot.
    public static void Shot(Vector3 muzzle) => PassForgePings.Ping(muzzle, new Color(1f, 0.32f, 0.22f), 2f, 6f);

    // An alarm the player should turn toward, for five seconds.
    public static void Alarm(Vector3 at) => PassForgePings.Ping(at, Color.red, 5f);

    // Sonar: enemies within 25 m show on every radar for four seconds, even out of sight.
    public static void Sonar(Vector3 player)
    {
        PassForgePings.Ping(player, new Color(0.4f, 0.9f, 1f), 4f, 25f, revealEnemies: true);
    }
}

A tutorial spotlight

A Spotlight Target dims the screen around its object while it is enabled.

using System.Collections;
using PassForge.Effects;
using UnityEngine;

// Dims the screen around one object for a tutorial step.
public class TutorialSpotlight : MonoBehaviour
{
    [SerializeField] PassForgeSpotlightTarget m_Target;   // on the object to point at, switched off in the scene

    public void Show(float seconds)
    {
        StopAllCoroutines();
        StartCoroutine(ShowFor(seconds));
    }

    IEnumerator ShowFor(float seconds)
    {
        m_Target.enabled = true;
        yield return new WaitForSecondsRealtime(seconds);   // real time, so it counts in a paused tutorial too
        m_Target.enabled = false;
    }
}

Turn damage numbers off as an option

PassForgeDamageNumbers.visible set to false hides every number and ignores new ones. Pass Forge does not save this choice, so the game keeps it.

using PassForge.Effects;
using UnityEngine;

// A Damage Numbers on or off option. Pass Forge does not save this choice, so the game keeps it.
public static class DamageNumberOption
{
    const string k_Key = "Damage Numbers";

    // For an options Toggle. Off hides every number at once and ignores new ones.
    public static void SetShown(bool shown)
    {
        PassForgeDamageNumbers.visible = shown;
        PlayerPrefs.SetInt(k_Key, shown ? 1 : 0);
    }

    // Once as the game starts, such as from a boot scene.
    public static void Restore() => PassForgeDamageNumbers.visible = PlayerPrefs.GetInt(k_Key, 1) == 1;
}