Skip to content

Pickup

namespace Griff.Scenes;
public sealed class Pickup : Component

Something to collect, with no code: coins, gems, hearts, keys. When something it accepts touches it (see Layers), it sends its Message with its Amount (a Counter adds it up), plays its Sound, spawns its Effect and disappears. Needs a collider on the same entity, usually a trigger.

This is a component: its saved properties are on its component page.

public int Amount { get; set; }

How much it’s worth: the data sent with its Message, and how many of its Item.

public string? Effect { get; set; }

A prefab spawned where it was, e.g. “Sparkle”: a burst of particles, a score popup.

public float Heal { get; set; }

Hit points it gives back to whoever collects it: a heart, a medkit. One that only heals (with no Item) is left where it is while their health is full.

public bool IsCollected { get; }

True once it has been collected (it disappears at the end of that frame).

public string? Item { get; set; }

An item it puts in the collector’s Inventory (one is added if it has none), e.g. “Key”, or its team’s items if it has none of its own (see Items): coins a hero collects for a strategy faction’s gold. Empty puts nothing there.

public string? Layers { get; set; }

The collision layers that can collect it, e.g. “Player”. Empty lets anything with a Body collect it.

public string? Message { get; set; }

The message sent when it’s collected, with Amount as its data. Empty sends nothing.

public string? Price { get; set; }

What it costs to collect, e.g. “10 Coin”: a shop’s wares. It stays where it is until whatever touches it can pay, and is paid from the collector’s items (or its team’s, see Items) as it’s collected. Empty is free.

public string? Sound { get; set; }

A sound played when it’s collected, e.g. “Sounds/coin.wav”.

public float Spin { get; set; }

Degrees per second it turns while waiting to be collected. 0 keeps it still.

public bool TintEffect { get; set; }

Gives the Effect’s particles this entity’s sprite color, so one sparkle suits every pickup.

public bool AcceptsLayer(string? layer)

True if something on collision layer layer can collect it.

public event Action<Entity>? Collected

Raised when it’s collected, with whatever collected it.