我正在用C#进行团结的小游戏.
到目前为止,我已设法设计级别并完成一些基本脚本.
目前我有一个触发器,它产生一个对象,并希望它一旦用户进入就播放和音频源.但是,因为我希望它是一个跳跃恐慌,触发器非常小,目前声音只播放IF我留在触发器.
我的代码如下:
using UnityEngine;
using System.Collections;
public class Spawner : MonoBehaviour {
public GameObject monster;
public AudioSource aud;
public AudioClip piano;
void Start ()
{
monster.SetActive (false);
aud = monster.GetComponent<AudioSource>();
}
void OnTriggerEnter(Collider other){
if (other.CompareTag ("Player")) {
monster.SetActive (true);
AudioSource.PlayClipAtPoint(piano, monster.transform.position);
}
}
void OnTriggerExit(Collider other){
if (other.CompareTag ("Player")) {
monster.SetActive (false);
}
Destroy (this.gameObject);
}
}
Run Code Online (Sandbox Code Playgroud)
我想知道是否有一种方法可以在人们离开扳机后保持声音播放.
谢谢!