Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

audiokit里需求一个方法,只是设定音频,但不播放 #125

Open
NyxJae opened this issue Feb 8, 2024 · 0 comments
Open

audiokit里需求一个方法,只是设定音频,但不播放 #125

NyxJae opened this issue Feb 8, 2024 · 0 comments

Comments

@NyxJae
Copy link

NyxJae commented Feb 8, 2024

audiokit里需求一个方法,只是设定音频,但不播放,后续用resume和pause控制播放
要实现一个开火功能,枪声是循环播放素材,开枪播放,熄火暂停.

   private void Start()
        {
            // 激活事件时开火

            // 取消激活事件时停火

            // 初始化音效
            _akmSound = AudioKit.PlaySound(Fxsound.AKM, true);
            _akmSound.Pause();
        }

private void Update()
        {
            if (!_isFire)
            {
                _akmSound.Pause();
            }
            else
            {
                if (Time.time - _lastFireTime > fireInterval)
                {
                    Debug.Log("Fire");
                    Fire();
                    _lastFireTime = Time.time;
                    _akmSound.Resume();
                }
            }
        }

这样写开始后声音还是会一开始就播放,因该是异步加载的问题

目前是这样实现的

private void Update()
        {
            if (!_isFire)
            {
                _akmSound?.Pause();
            }
            else
            {
                if (Time.time - _lastFireTime > fireInterval)
                {
                    if (_isFirstFire)
                    {
                        _isFirstFire = false;
                        // 初始化音效
                        _akmSound = AudioKit.PlaySound(Fxsound.AKM, true);
                    }

                    Debug.Log("Fire");
                    Fire();
                    _lastFireTime = Time.time;
                    _akmSound.Resume();
                }
            }
        }
@NyxJae NyxJae closed this as completed Feb 8, 2024
@NyxJae NyxJae reopened this Feb 9, 2024
@NyxJae NyxJae closed this as completed Feb 9, 2024
@NyxJae NyxJae reopened this Feb 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant