AudioSource

private AudioSource a;

public AudioClip b, c;

public GameObject obj;

// Use this for initialization

void Start () {
a = obj.AddComponent();

}

// Update is called once per frame

void Update () {
if (Input.GetKey(KeyCode.W))
{
a.clip = b;
a.Play();
}
if (Input.GetKey(KeyCode.S))
{
a.clip = c;
a.Play();
}
}

你可能感兴趣的:(unity)