how can i make it so when i pick up an object it plays an audio clip. I have got he pick up system working here is my script,
function OnTriggerEnter (col : Collider) {
if(col.gameObject.tag == "Player") {
Inventory2.inventoryArray[0]++;
Destroy(this.gameObject);
}
}
As far as i understand, the object to pick up is the one in control of the action.
But if you did it the other way round, you could just attach the audiosource component to your player and let that play the pickup sound in
OnTriggerEnter of the player.
I suggest you do it that way, as i personally think its cleaner anyway, also because if you play the clip on the pickup object and immediately destroy it you’d hear no sound, obviously.
But then again you could also col.gameObject.sendMessage(“PlayPickupSound”) the player (and add the respective function).