C# Unity 3D:足迹声音在前几毫秒循环播放,而不是播放完整的声音然后循环播放
当我在游戏中移动时,我的声音并没有被完全播放,而是在循环中播放几毫秒 这是我的密码:C# Unity 3D:足迹声音在前几毫秒循环播放,而不是播放完整的声音然后循环播放,c#,unity3d,audio,C#,Unity3d,Audio,当我在游戏中移动时,我的声音并没有被完全播放,而是在循环中播放几毫秒 这是我的密码: using System.Collections; using System.Collections.Generic; using UnityEngine; public class Footsteps : MonoBehaviour { public AudioSource audioSource; public PlayerMovement pM; void Start()
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Footsteps : MonoBehaviour
{
public AudioSource audioSource;
public PlayerMovement pM;
void Start()
{
audioSource.Stop();
}
void Update()
{
PlaySound();
}
public void PlaySound()
{
if (Input.GetKey(KeyCode.W))
{
audioSource.Play();
}
else
{
audioSource.Stop();
}
}
}
录像带
如有任何建议,将不胜感激 只要按下键,就会调用方法
Input.GetKey()
。要做到这一点,可以使用Input.GetKeyDown()
如下示例:
public void PlaySound()
{
if (Input.GetKeyDown(KeyCode.W))
{
audioSource.Play();
}
else if(Input.GetKeyUp(KeyCode.W))
{
audioSource.Stop();
}
}
有其他的方法来消除这种声音,但这种简单的方法应该可以奏效
参考资料: