you can access AudioSource component of your gameObject using audio property. attach an audioSource to your gameObject and even add a @RequireComponent tag to your script because any object that wants to play sounds should have an audio source attached.
var soundP : AudioClip;
function OnMouseOver()
{
if(audio.clip != soundp) audio.clip = soundP;
if (!audio.isPlaying)
{
audio.Play();
}
}
there is a play function that takes the audio clip to play as an argument, in that way you don’t need to set the clip as the clip of the audio source. i think it was PlayOneShot.
when you type AudioSource you are writing the name of the class which only allows you to access static variables/functions. you need the reference to the audio source component that you can get by using audio property.
to tell the script to attach an audio source automatically to your gameObject if it don’t have any write this attribute in your script.
@RequireComponent(AudioSource)
in this way when you add this component an audiosource will be added autoamtically if needed.