Audio not playing

I have an issue, where the audio wont play. its on a spot light object inside a camera. the spot light has the following script and has audio source components and the player object (houses the camera) has a audio listener. YET I HEAR NO SOUND…

using UnityEngine;
using System.Collections;

public class torchscript : MonoBehaviour {

public bool on = false;
public AudioClip FlashOff;

	
void Update()
{
    if(Input.GetKeyDown(KeyCode.F))
        on = !on;
    if(on) 
        light.enabled = true;

		else if(!on) 
        light.enabled = false;
		audio.PlayOneShot(FlashOff, 0.7F);

	}
}

i know theres been a lot of problems with this for people before…

I think the problem is that you call PlayOneShot outside of your if. So it is effectively called 60 times a second (assuming your game runs at 60FPS). Please include it inside of the if statement by introducing curly brackets:

if(on)
{
    light.enabled = true;
}
else
{
    light.enabled = false;
    audio.PlayOneShot(FlashOff, 0.7F);
}

Of course only curly brackets after else are necessary. The pair after if can be omitted, but I strongly suggest to always use them - this IMO makes your code more readable. Besides, there’s no need to use

else if(!on)

because in this case just else is enough.