I have a “point” prefab. This prefab has a sound and i put it in a Audio Clip for reuse. But the Unity generate this error…
MissingComponentException: There is no ‘AudioSource’ attached to Point… there is my code…
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(AudioSource))]
public class PointScript : MonoBehaviour {
public int value;
public AudioClip audioPoint;
void OnTriggerEnter2D(Collider2D other) {
PlayerScript playerScript;
if( playerScript = other.GetComponent<PlayerScript> ()){
playerScript.addScore (value);
die ();
}
}
public void die(){
audio.PlayOneShot(audioPoint);
Destroy (gameObject);
}
}