Hello everyone. I’m fairly new to Unity but pretty advanced in other scripts such as JS and AS.
So I have a prefab with this script attached:
#pragma strict
var prospectTime : int;
var prospectAudio : AudioClip;
private var time : float = 0.0f;
function OnMouseDown () {
if (Vector3.Distance(transform.position, GameObject.FindGameObjectWithTag("Player").transform.position) < 6)
time = 0.1f;
}
function Update () {
if (time > 0) {
time += 1 * Time.deltaTime;
}
if (time > prospectTime) {
activate();
}
}
function activate () {
var zone : Zone = transform.parent.transform.parent.transform.parent.GetComponent(Zone);
var a = transform.parent.transform.parent.name.Split(":"[0]);
if (zone.activateData(transform.parent.name, int.Parse(a[1]), int.Parse(a[2])) == true) {
AudioSource.PlayClipAtPoint (prospectAudio, transform.position);
transform.parent.active = false;
}
time = 0.0f;
}
function OnMouseUp () {
time = 0.0f;
}
This works, however if i try to play the sound with
audio.Play(prospectAudio);
it will throw an error:
BCE0023: No appropriate version of ‘UnityEngine.AudioSource.Play’ for the argument list ‘(UnityEngine.AudioClip)’ was found.
audio.PlayOneShot(prospectAudio);
also throws an error:
MissingComponentException: There is no ‘AudioSource’ attached to the “Coal1” game object, but a script is trying to access it.
In inspector I did drag the audio on the script’s prospectAudio variable.
What’s wrong? I would like to use the audio.Play and audio.PlayOneShot but it seams I can’t
Can someone explain please?