我需要一些编码方面的帮助。到目前为止,我可以让音频剪辑在第一个游戏对象被触发时使用,但在将clip2和clip3添加到第二个和第三个游戏对象时遇到了一些问题。有什么建议么?
public class ControllerInput : MonoBehaviour {
public Animator anim;
public Transform vrTransform;
public AudioClip clip;
public AudioClip clip2;
public AudioClip clip3;
public AudioClip clip4;
public AudioSource audioSource;
private AudioSource audioEngine;
void Start() {
audioSource = GetComponent<AudioSource>();
audioSource.clip = clip;
}
void Update() {
if (OVRInput.Get(OVRInput.Button.PrimaryIndexTrigger))
{
audioSource.Play();
RaycastGun();
}
}
private void RaycastGun()
{
RaycastHit hit;
if (Physics.Raycast(vrTransform.position, vrTransform.forward, out hit))
{
if (hit.collider.gameObject.CompareTag("Cube"))
{
Destroy(hit.collider.gameObject);
}
if (hit.transform.gameObject.tag == ("Cube"))
anim.Play("start");
audioSource = GetComponent<AudioSource>();
audioSource.clip = clip2;
}
if (hit.transform.gameObject.tag == ("drillbit"))
anim.Play("drillbit");
audioSource = GetComponent<AudioSource>();
audioSource.clip = clip3;
}
}