using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AudioTest : MonoBehaviour
{
public AudioClip bgm;
public AudioClip se;
public AudioSource play;
// Start is called before the first frame update
void Start()
{
play = GetComponent<AudioSource>();
play.clip = bgm;
play.loop = true;
play.Play();
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
//判断是否正在播放
if (play.isPlaying)
{
//暂停
//play.Pause();
//停止
play.Stop();
}
else
{
//取消暂停
//play.UnPause();
//开始
play.Play();
}
}
if (Input.GetMouseButtonDown(0))
{
//只播放一次
play.PlayOneShot(se);
}
}
}
unity音频播放demo
最新推荐文章于 2024-11-04 23:02:15 发布