Can you help me with my flashlight sound?

do you have skype to make this easier so i can share my current code? MagicRecon is my skype

This is the code

function Update () {

AudioClip sound;

if (Input.GetKeyDown(“f”)) {
if (light.enabled == true)

     light.enabled = false;
     else
     
     light.enabled = true;
     }

if (Input.GetKeyDown(“f”)) {
audio.PlayOneShot(sound);
}
}

AudioClip sound;

function Update(){
  if (Input.GetKeyDown("f")) {
    light.enabled = !light.enabled;
    audio.PlayOneShot(sound); 
  }
}

Edit: I added the Update as I thought it would be obvious that it has to be in there.

ok so i typed up this a few seconds ago however its still not playing the sound that is in the audiosource

private var lightSource : Light;
var soundTurnOn : AudioClip;
var soundTurnOff : AudioClip;

function Start () {
lightSource = GetComponent(Light);
}

function Update () {
if (Input.GetKeyDown(KeyCode.F)) ToggleFlashLight();
}

function ToggleFlashLight () {

lightSource.enabled=!lightSource.enabled;

//Audio
if (lightSource.enabled) {
   audio.clip = soundTurnOn;
} else {
   audio.clip = soundTurnOff;
}
audio.Play();

}

no wait my friend who has never scripted in his life let alone wipe his own ass has solved it!

All this code:

AudioClip sound;
 
if (Input.GetKeyDown("f")) {
    light.enabled = !light.enabled;
    audio.PlayOneShot(sound);
}

Is not sitting inside your Update funciton for starters, maybe try:

AudioClip sound;
function Update () {
   
  if (Input.GetKeyDown("f")) {
     audio.PlayOneShot(sound);
     if (light.enabled == true)
         light.enabled = false;
     else
         light.enabled = true;
  }
}

If you’re going to play the sound regardless it doesn’t need two if statements just get it to play the sound whenever f is hit. I have no idea what the last if statement is meant to achieve so I’ve left it out as I assume it was just supposed to turn the light on or off which the first statement does.

Is that right because its still not working yet

function Update () {

  if (Input.GetKeyDown("f")) {
     if (light.enabled == true)
         light.enabled = false;
     else
         light.enabled = true;
  }

if (Input.GetKeyDown("f")) { 
   audio.PlayOneShot(sound); 
} }

 AudioClip sound;
 
if (Input.GetKeyDown("f")) {
    light.enabled = !light.enabled;
    audio.PlayOneShot(sound);
}

Its still coming up with error’s such as asking for semi colons