Skip to content

Instantly share code, notes, and snippets.

@OutlawGameTools
Last active August 29, 2015 14:17
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/3b177db6bc386e2e7905 to your computer and use it in GitHub Desktop.
Save OutlawGameTools/3b177db6bc386e2e7905 to your computer and use it in GitHub Desktop.
CS109 - Attach to a coin or other pickup item. Destroys the item and optionally shows a particle effect and plays sound FX.
#pragma strict
public var coinEffect : GameObject;
private var soundFX : AudioSource;
function Start()
{
soundFX = GetComponent.<AudioSource>();
}
function OnTriggerEnter2D (other : Collider2D)
{
if (other.CompareTag("Player"))
{
if (coinEffect)
Instantiate(coinEffect, transform.position, transform.rotation);
if (soundFX)
{
print("playing AudioSource");
soundFX.Play();
}
//gameObject.renderer.enabled = false; // only works in Unity 4.x
gameObject.GetComponent.<Renderer>().enabled = false; // will work in Unity 4 & 5
Destroy(gameObject, 1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment