- Home /
All i want to do is click gameobject, play sound & destroy object as to pickup an item
void OnMouseDown() {
GetComponent<AudioSource>().Play();
{
Renderer=false;
}
}
}
That's what I cant figure out, in theory it would work, I also tried destroying the object & that didn't work either. I thought maybe it was because it was destroying the object therefore destroying the audio clip attached, so I thought I would go with the render option however this isn't working either, it will play the sound with the above code but won't make the object disappear. Please bear with me I'm about a week old with unity & c# or any kind of coding whatsoever
Please post all non-answers in the form of a comment. Thanks,
If you destroy an object with an AudioSource that is playing, the sound will stop. Either put the AudioSource on a different object, or move it to a new empty object when you're going to destroy the original object.
$$anonymous$$uch of the code above is nonsense; I'd suggest spending a week or two with the lessons on-site and any other learning materials you can get your hands on.
Answer by ExplodingCookie · Mar 28, 2015 at 08:11 PM
I don't have much experience in C# so this is in JavaScript
var pickupSound : AudioClip;
function OnMouseDown () {
AudioSource.PlayClipAtPoint(pickupSound, transform.position);
//Do your pickup action
GameObject.Destroy(gameObject);
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613191503im_/https://answers.unity.com/themes/thub/images/avi.jpg)