我正在制作一个 2d 游戏,它有硬币,当玩家触摸硬币时,我试图让硬币消失并发出叮当声。问题是硬币消失但没有声音。
using UnityEngine;
using System.Collections;
public class coins : MonoBehaviour {
static int coin = 0;
AudioClip coinSound;
void Start()
{
coin = 0;
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "Player")
{
coin++;
audio.PlayOneShot(coinSound);
StartCoroutine(Ding());
Destroy(this.gameObject);
}
}
void OnDisable(){
PlayerPrefs.SetInt ("coin", coin);
}
IEnumerator Ding(){
yield return new WaitForSeconds (0.4F);
}
}