Skip to content

Instantly share code, notes, and snippets.

@OutlawGameTools
Last active February 15, 2019 22:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OutlawGameTools/f7bc109ceadd2b86ce4c to your computer and use it in GitHub Desktop.
Save OutlawGameTools/f7bc109ceadd2b86ce4c to your computer and use it in GitHub Desktop.
CS109 C# - Attach to a coin or other pickup item. Destroys the item and optionally shows a particle effect.
using UnityEngine;
using System.Collections;
public class Pickup : MonoBehaviour {
public GameObject pickupEffect; // optional prefab particle effect
void OnTriggerEnter2D (Collider2D other)
{
if (other.CompareTag("Player"))
{
if (pickupEffect)
Instantiate(pickupEffect, transform.position, transform.rotation);
Destroy(gameObject); // get rid of the pickup object
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment