Pass ForgeDocs Product page

Scripting

Slow motion and pause

Hit stop and slow motion

PassForgeSlowMotion.HitStop freezes the game for real seconds, PassForgeSlowMotion.Play slows it and eases it back, and PassForgeSlowMotion.Stop ends both at once.

using PassForge.Effects;

// Time effects from a script, the ones Hit Stop and Slow Motion steps play in a moment.
public static class TimeEffects
{
    // The game stands still for real seconds; a tenth of a second or less reads as a hit.
    public static void HeavyBlow() => PassForgeSlowMotion.HitStop(0.08f);

    // A third of full speed for 1.5 real seconds, then back to full speed over half a second.
    public static void FinishingMove() => PassForgeSlowMotion.Play(0.3f, 1.5f, 0.5f);
}

Pause the game

Moments, transitions, damage numbers and the VHS rewind count real time, so they keep playing in a pause menu.

using PassForge.Effects;
using UnityEngine;

// A pause menu. Call TogglePause from your pause key or button.
public class PauseMenu : MonoBehaviour
{
    [SerializeField] GameObject m_Menu;   // with a frosted PF Panel behind it

    bool m_Paused;

    public void TogglePause() => SetPaused(!m_Paused);

    public void SetPaused(bool paused)
    {
        m_Paused = paused;

        // Ends a hit stop or slow motion first, so the game resumes at full speed.
        if (paused)
            PassForgeSlowMotion.Stop();

        Time.timeScale = paused ? 0f : 1f;
        m_Menu.SetActive(paused);
    }

    // Leaving the scene, or Play Mode, while paused would leave time stopped.
    void OnDisable()
    {
        if (m_Paused)
            Time.timeScale = 1f;
    }
}

A frosted pause backdrop

A PF Panel shows the scene behind it frosted, pixelated, in black and white and more. Adding one to an Image in the editor is the usual way; this builds one from code.

using PassForge.Effects;
using UnityEngine;
using UnityEngine.UI;

// Builds a frosted full screen backdrop for a pause menu from code. Adding a PF Panel to an Image in the editor
// does the same. Needs the Unity UI package (com.unity.ugui).
public static class PauseBackdrop
{
    public static GameObject Create()
    {
        // A PF Panel shows the blurred scene only on a Screen Space - Overlay canvas.
        var canvasObject = new GameObject("Pause Canvas", typeof(Canvas));
        var canvas = canvasObject.GetComponent<Canvas>();
        canvas.renderMode = RenderMode.ScreenSpaceOverlay;
        canvas.sortingOrder = 100;

        var backdrop = new GameObject("Backdrop", typeof(RectTransform), typeof(CanvasRenderer), typeof(Image));
        backdrop.transform.SetParent(canvasObject.transform, false);
        var rect = (RectTransform)backdrop.transform;
        rect.anchorMin = Vector2.zero;
        rect.anchorMax = Vector2.one;
        rect.offsetMin = Vector2.zero;
        rect.offsetMax = Vector2.zero;
        backdrop.GetComponent<Image>().raycastTarget = false;

        var panel = backdrop.AddComponent<PassForgePanel>();
        panel.style = PanelStyle.Frosted;
        panel.blur = 0.85f;
        panel.tint = new Color(0.02f, 0.03f, 0.05f, 0.35f);
        panel.cornerRadius = 0f;
        panel.borderWidth = 0f;
        panel.shadowColor = Color.clear;

        canvasObject.SetActive(false);   // the pause menu shows it
        return canvasObject;
    }
}