Adding Collectibles and Pickups
Use this skill when the user wants items to collect, pickups, coins, power-ups, or inventory items.
Trigger Phrases
- "collect", "pickup", "pick up"
- "coins", "gems", "stars", "points"
- "power-up", "health pack", "ammo"
- "items", "loot", "treasure"
Implementation Checklist
Create Collectible GameObject
- Visual (coin, gem, glowing orb, etc.)
- Collider set as TRIGGER (isTrigger = true)
- Rigidbody (isKinematic = true, useGravity = false) for trigger detection
- Tag appropriately ("Coin", "PowerUp", etc.)
Add Collection Script
- OnTriggerEnter to detect player
- Effect on collect (add score, heal, etc.)
- Feedback (sound, particles)
- Destroy or disable after collection
Visual Polish
- Spinning animation
- Bobbing up/down
- Glow or particle effect
- Distinct color (gold for coins, red for health, etc.)
Multiplayer Setup (Normcore)
- Add RealtimeView
- Sync collection state (so collected items disappear for all)
- Consider: first-touch-owns for collection
Scoring/Inventory
- Create or update score manager
- UI to display count/score
Collection Script
public class Collectible : MonoBehaviour
{
public int value = 1;
public CollectibleType type = CollectibleType.Coin;
void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Player"))
{
Collect(other.gameObject);
}
}
void Collect(GameObject player)
{
switch (type)
{
case CollectibleType.Coin:
ScoreManager.Instance.AddScore(value);
break;
case CollectibleType.Health:
player.GetComponent<Health>()?.Heal(value);
break;
case CollectibleType.PowerUp:
player.GetComponent<PowerUpHandler>()?.ApplyPowerUp(this);
break;
}
// Feedback
// AudioManager.Instance.Play("collect");
// Instantiate(collectEffect, transform.position, Quaternion.identity);
Destroy(gameObject);
}
}
public enum CollectibleType { Coin, Health, PowerUp, Key, Ammo }
Visual Effects
Spinning
void Update()
{
transform.Rotate(0, 90 * Time.deltaTime, 0);
}
Bobbing
private Vector3 startPos;
void Start() => startPos = transform.position;
void Update()
{
transform.position = startPos + Vector3.up * Mathf.Sin(Time.time * 2) * 0.2f;
}
Combined
void Update()
{
transform.Rotate(0, 90 * Time.deltaTime, 0);
transform.position = startPos + Vector3.up * Mathf.Sin(Time.time * 2) * 0.2f;
}
Score Manager (Singleton)
public class ScoreManager : MonoBehaviour
{
public static ScoreManager Instance;
public int score { get; private set; }
public event System.Action<int> OnScoreChanged;
void Awake()
{
if (Instance == null) Instance = this;
else Destroy(gameObject);
}
public void AddScore(int amount)
{
score += amount;
OnScoreChanged?.Invoke(score);
}
}
Output to User
Explain simply:
- "I added coins you can collect by walking into them"
- "Each coin adds 10 points to your score"
- "The coins spin and float so they're easy to spot"
Source: gamekit-agent/gamekit-cli — distributed by TomeVault.