Last active
August 29, 2015 14:17
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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