gameObject to play sound on deletion, won't work...

I’m trying to “collect” an object, since I no longer need it in the world I delete it with “Delete(gameObject);” and it works perfect. Now I want to play a sound as well, so I have and it works but once the object is deleted the rest of the collectables can’t find the audioSource, even if I attach it to them… I’ve tried attaching the audio to an inanimate object like a Shovel that’s part of the scenery but it wont work. Can someone help me to properly attach audio and link it from another object?

I think my problem is that the script I am using is deleting the gameObject and anything it’s linked to/with.


var PageCount : GUIText;
var Count : int;
var Pickup : AudioSource;

function Touched(hit:RaycastHit)
{
	Destroy(gameObject);
}

function Update () {
	
if ( Input.GetMouseButtonDown(0)){
   	var hit : RaycastHit;
   	var ray : Ray = Camera.main.ScreenPointToRay (Input.mousePosition);
   	
    if (Physics.Raycast (ray, hit, 0.8))
      {
		 hit.transform.SendMessage("Touched", hit, SendMessageOptions.DontRequireReceiver);
         Count ++;
         PageCount.guiText.text = Count.ToString();
         audio.Play();
         audio.loop = false;
      }
   }
	
}

Change the type of Pickup to AudioClip assign the clip your trying to play in the inspector and use the audio.PlayOneShot().

var Pickup : AudioClip;

if (Physics.Raycast (ray, hit, 0.8))
      {
        hit.transform.SendMessage("Touched", hit, SendMessageOptions.DontRequireReceiver);
         Count ++;
         PageCount.guiText.text = Count.ToString();
         audio.PlayOneShot(Pickup);
        
      }

You need to make sure the object that is playing the sound also has a AudioSource component attached to it.