Play a sound when an object disappears

I am trying to add a sound when an object disappears

here is the script , I just added “audio.Play(droplet);” , i now get compiling error message and even deleting the line i still get a compiling error, i can’t write code so if any one can fix this i would be very happy, thanks.

using System.Collections;

public class pickUps : MonoBehaviour {

public float  speed;
public GUIText countText;
public GUIText winText;
private int count;


void start ()
{
	count = 0;
	winText.text = "";
	SetCountText ();
	
}

void FixedUpdate ()
{
	gameObject.GetComponent<Renderer>().material.color = Color.green;
	float moveHorizontal = Input.GetAxis("Horizontal");
	float moveVertical = Input.GetAxis("Vertical");
	
	Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
	
	GetComponent<Rigidbody>().AddForce(movement * speed * Time.deltaTime);
}

void OnTriggerEnter(Collider other) 
{
	if(other.gameObject.tag == "PickUp") 
	{
		audio.Play(droplet);
		other.gameObject.SetActive(false);
		count = count + 1;
		SetCountText ();
	}
}
void SetCountText ()
{
	countText.text = "Count: " + count.ToString();
	if(count >= 12)
	{
		winText.text = "Task completed  - Press Escape to Quit";
		
	}
}

}

I got the script to run again with out the audio.Play part

so just need help with that bit please.

using UnityEngine; using System.Collections;

public class pickUps : MonoBehaviour {

public float speed;
public GUIText countText;
public GUIText winText;
private int count;

void start ()
{
count = 0;
winText.text = “”;
SetCountText ();

}

void FixedUpdate ()
{
gameObject.GetComponent().material.color = Color.green;
float moveHorizontal = Input.GetAxis(“Horizontal”);
float moveVertical = Input.GetAxis(“Vertical”);

 Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
 
 GetComponent<Rigidbody>().AddForce(movement * speed * Time.deltaTime);

}

void OnTriggerEnter(Collider other)
{
if(other.gameObject.tag == “PickUp”)
{
other.gameObject.SetActive(false);
count = count + 1;
SetCountText ();
}
}
void SetCountText ()
{
countText.text = "Count: " + count.ToString();
if(count >= 12)
{
winText.text = “Task completed - Press Escape to Quit”;

 }

}
}

Add comment · Share · Accept

this script runs but doesn’t play the sound ?

using UnityEngine;
using System.Collections;

public class pickUps : MonoBehaviour {

public float  speed;
public GUIText countText;
public GUIText winText;
public AudioClip droplet;
private int count;
private AudioSource source;


void start ()
{
	source = GetComponent<AudioSource>();
	count = 0;
	winText.text = "";
	SetCountText ();
	
}

void FixedUpdate ()
{
	gameObject.GetComponent<Renderer>().material.color = Color.green;
	float moveHorizontal = Input.GetAxis("Horizontal");
	float moveVertical = Input.GetAxis("Vertical");
	
	Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
	
	GetComponent<Rigidbody>().AddForce(movement * speed * Time.deltaTime);
}

void OnTriggerEnter(Collider other) 
{
	if(other.gameObject.tag == "PickUp") 
	{
		other.gameObject.SetActive(false);
		count = count + 1;
		SetCountText ();
		source.PlayOneShot(droplet,1F);
	}
}
void SetCountText ()
{
	countText.text = "Count: " + count.ToString();
	if(count >= 12)
	{
		winText.text = "Task completed  - Press Escape to Quit";
		
	}
}

}