Created
February 11, 2015 22:13
-
-
Save OutlawGameTools/189406d7cc8316c5c784 to your computer and use it in GitHub Desktop.
Unity: Attach to game objects that can be picked up (collider2d, isTrigger). Play audio if it exists on game object.
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 pickupValue : int = 5; | |
function OnTriggerEnter2D(other : Collider2D) | |
{ | |
var gObj : GameObject = other.gameObject; | |
var clip : AudioClip; | |
if (gObj.CompareTag("Player")) | |
{ | |
// Add pickupValue to total treasure amount | |
if (gameObject.audio) | |
{ | |
clip = gameObject.audio.clip; | |
AudioSource.PlayClipAtPoint(clip, new Vector3 (5, 1, 2)); | |
} | |
Debug.Log("Grabbed treasure! " + gameObject.name + " " + pickupValue + " points!" ); | |
Destroy(gameObject); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment