an instance of type UnityEngine.AudioSource is required to access non static member Play

i have this code and i get the error above

#pragma strict

function Start () {
var impacter : AudioClip;

}

function OnMouseDown(){
	AudioSource.Play(
	Debug.Log("audio is working");
}de here`

Well, there’s a few things wrong.

  1. You haven’t ended the “Play()” function reference, nor the line.
  2. The error means that you have to be accessing a specific audio source. At the moment, you are accessing the AudioSource class, which you can think of as a script that isn’t attached to anything (not quite correct, but for now its fine).

Instead it should be;

#pragma strict

var audioSource : AudioSource;    //Set this in the inspector

function Start ()
{
    var impacter : AudioClip;    //What is this meant to be doing?
}

function OnMouseDown ()
{
    audioSource.Play ();    //Play that specific audio source
    Debug.Log ("Audio is working.");
}