Simple collectables and collectors for 2d unity games
- Add 2DCollectables to your unity project
- Add
Collider2Dcomponents (of any shape) to your collectable objects - Add
Collectablescripts to your collectable objects - Add a Collector to your character (collector) or implement your own by deriving from
ICollector - Done
These live under Examples
Note: object
Collectable1andCollectable2are static 2d colliders, whileCollectable3andCollectable4are 2d trigger colliders. Both work great.
A simple collector demo in which a character (controlled with WASD) moves around and collects shapes. On collection, the object name is written to the console, and it is promptly destroyed.
A simple collector demo in which a character (controlled with WASD) moves around and collects shapes until a max of 5 have been collected. The character can consume shapes (from most recent to least recent pickup) by pressing SPACE - at which point the object name is written to the console, and it is promptly destroyed.
It leverages CollectionIconVisual to render a small icon of the collectable currently at the "top" of the stack. Note that this component has a SpriteRenderer that renders to the UI layer, so that it always appears on top of other objects (which live in the Default layer).
A scene capable of spawning collectables at a random interval, and which does not spawn collectables if a collector is nearby (within 1 unit). The spawner chooses from a collection of prefab collectables and spawns a new one if the spawn position doesn't already have a collectable out, and the collector is not nearby.
It leverages RangeRandomizer to change the spawn intervals within a given range independently of one-another.
Note: this is a
betafeature that I am considering changing the API of. Plan accordingly.
A scene that is exactly like the Spawner scene, but uses 3d game components. This makes the title of this library irrelevant, but it also lets you leverage the collectable system if you're using 3d colliders.
MIT
