Add audio script errors.

Heya, I’m having abit of a problem with this code, Everything in this code works when i remove “Audio codes” but soon as i want to add the Audio back in the code it as problems this code works in Unity3/4 but Unity 5 it doesn’t want to work.

Thank you if anyone can help this is Java script

#pragma strict

var torchClick : AudioClip;

var flashLight : Light;

function Start()
{
    flashLight.light.enabled = false;
    flashLight.light.intensity = 8;
}

function Update()
{
    if(flashLight.light.enabled == true)
    {
        flashLight.light.intensity -= 0.1 * Time.deltaTime / 5;
        Debug.Log(flashLight.light.intensity);
    }
   
    if(Input.GetKeyDown("f"))
    {   
        AudioClip.PlayOneShot(torchClick);
       
        if(flashLight.light.enabled == false)
        {
            flashLight.light.enabled = true;
        }
       
        else
        {
            flashLight.light.enabled = false;
        }
    }
}
AudioClip.PlayOneShot(torchClick);

PlayOneShot is a function of an AudioSource… there is no such function of an AudioClip… I really doubt this code works in any version of unity :face_with_spiral_eyes:

an analogy is that AudioSource is the “player”, you tell it to play a “track” (i.e. the audiclip). Tracks don’t miraculously play themselves without something to play them on.

https://unity3d.com/learn/tutorials/modules/beginner/live-training-archive/sound-effects-scripting