我正在尝试编写一个脚本,当你击中敌人时它会播放声音,问题是我无法让它播放它看到音频源的声音,但我的脚本不会将剪辑传递给它。
这是我目前拥有的代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Audio;
public class makeanoise : MonoBehaviour
{
public AudioClip hurtSound;
public AudioSource soundSource;
private void Update()
{
if (!soundSource.isPlaying)
{
soundSource.clip = hurtSound;
soundSource.Play();
}
}
}
Run Code Online (Sandbox Code Playgroud)
你如何让音频源播放声音?因为连我的队友都不知道这样做