I already have a coin prefab and coin spawn prefab. I want that coins wil have the sound effect when I pick up them. I wrote the script and I apply this for the coin prefab:
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(AudioSource))]
public class PickupCoinScript : MonoBehaviour {
HUDScript hud;
public AudioClip impact;
void OnTriggerEnter2D(Collider2D other)
{
if(other.tag == "Player")
{
hud = GameObject.Find("Main Camera").GetComponent<HUDScript>();
hud.IncreaseCoin(1);
audio.PlayOneShot(impact, 0.7F);
Destroy(this.gameObject);
}
}
}
But when i start playing, sound play when coins spawn, not when I pick up them… How to solve this problem? Where I make a mistake? P.S. sorry for bad English