Audio Clip not working.

Hi,
so i have a ship gameobject (sprite), and i have this script attached…
using UnityEngine;
using System.Collections;

public class PlayerController : MonoBehaviour {
    public ParticleSystem explosion1;
    public AudioSource DestroySound;
    public float Speed; 
    public float padding = 1f;
    public GameObject laserBeam;
    public float laserSpeed;
	public float firingRate = 0.2f;
    float xmin;
    float xmax;
    public float health;
	// Use this for initialization
	void Start () {
	float distance = transform.position.z - Camera.main.transform.position.z;
	//camera.main is the main camera and lets us act on the main camera
	   Vector3 leftmost = Camera.main.ViewportToWorldPoint(new Vector3(0,0,distance ));
		// we have used camera.main.viewporttoworld poin to workoout the boundaries.
		Vector3 rightmost = Camera.main.ViewportToWorldPoint(new Vector3(1,0,distance ));
		xmin = leftmost.x + padding;
		xmax = rightmost.x - padding;
	}
	void Fire() {
	Vector3 offset = new Vector3(0,1,0);
		GameObject beam = Instantiate(laserBeam, transform.position+offset, Quaternion.identity) as GameObject ;
		//Quaternion.identity means that there will be no rotation at all. return whatever it gets as gameobject
		beam.rigidbody2D.velocity = new Vector3(0, laserSpeed, 0);
	}
	// Update is called once per frame
	void Update () {
		
		if (Input.GetKeyDown(KeyCode.Space)){
		  InvokeRepeating ("Fire", 0.000001f, firingRate);
			
		}
		if(Input.GetKeyUp(KeyCode.Space)) {
		CancelInvoke("Fire") ;
		}
		
		
		
		if (Input.GetKey(KeyCode.LeftArrow)) {
			transform.position += Vector3.left * Speed * Time.deltaTime;
			//The time in seconds it took to complete the last frame (Read Only).
			//Use this function to make your game frame rate independent.
		}else if (Input.GetKey(KeyCode.RightArrow)) {
			transform.position += Vector3.right * Speed * Time.deltaTime;
			//+= means incriment or add to.
			// VECTOR3- Representation of 3D vectors and points.
			//This structure is used throughout Unity to pass 3D positions and directions around. It also contains functions for doing common vector operations.
		}
		//restrict the player to the game space
		float newx = Mathf.Clamp(transform.position.x, xmin, xmax);
		transform.position = new Vector3(newx, transform.position.y, transform.position.z);
	}
	
	void OnTriggerEnter2D(Collider2D collider){
		Projectile missile = collider.gameObject.GetComponent<Projectile>();

		if(missile){
			Debug.Log ("Player collision");
			health -= missile.getDamage();
			missile.Hit ();
			
			if (health <= 0){
				DestroySound.Play();
			    explosion1.transform.position = this.transform.position;
				
				explosion1.Play();
				explosion1.enableEmission = true;
				
				Destroy(gameObject);
				
			}
			Debug.Log("Hit by a laser");
			
		}
		
	}
}

the problem is that when health becomes 0, the audio clip does not play. please help.

thanks in advance.

What have you tried to debug? Are any errors thrown? Is your AudioSource assigned? Does it have an AudioClip? Are the volumes and other settings correct? Can you test your sound be enabling “play on awake” on the AudioSource? If everything works, can you verify that you actually reach the statement in your code? Set breakpoints or a print statement to find out if the code is actually executed. If everything gets to confusing, start a new test scene with the most simple setup. Only one AudioSource with a clip and a script that plays it. Then build up the other code around it.

@MNM123 Do you by accident have the audio source on the same game object?

If so you would want to use PlayOneShot and a temporary audio source game object (speaker) that you move into the position where the audio is meant to come from (if 3D) because the .Play command relies on the game object for continous positioning in space among for various reasons so if you remove the game object with the audio source, the audio is gone too (you call Destroy(gameObject)).

@MNM123 It seems like that you are destroying the gameObject too quickly that the audiosource doesnt even have time to play.

First the audio.Play only work on background music or other related… I advise you you use Playonshot() method…

Public AudioClip sound; /// drag the sound on inspector.
////////
void method()
{
audio.PlayOnShot(sound,1)///// audio is audioSurce datatype varible…
}