大家好,我试图在游戏中移动时发出行走声音。我尝试了很多方法和简单的audio.clip = walkSound和audio.Play,并且非有效。关于如何播放声音的任何想法?
public float walkSpeed = 5.0f;
public float slowPentaly = 0.5f;
public float gravity = 20.0f;
public float run = 2.0f;
private Vector3 moveDirection = Vector3.zero;
public AudioClip walkSound;
void Start()
{
//transform.position = new Vector3(0,1.7f,0);
}
void OnControllerColliderHit(ControllerColliderHit hit)
{
if (hit.gameObject.tag == "Shard") {
moveDirection *= slowPentaly;
Debug.Log("You are slow");
}
}
void Update()
{
CharacterController controller = GetComponent<CharacterController> ();
if (controller.isGrounded) {
moveDirection = new Vector3(Input.GetAxis ("Horizontal"), 0, Input.GetAxis ("Vertical"));
moveDirection = transform.TransformDirection (moveDirection);
moveDirection *= walkSpeed;
if (Input.GetKeyDown(KeyCode.LeftShift))
moveDirection *= run;
}
moveDirection.y -= gravity * Time.deltaTime;
controller.Move (moveDirection * Time.deltaTime);
}
}
答案 0 :(得分:0)
audioclip是要播放的声音文件。这被放入播放它的音频源中。你不能&#34;只是&#34;播放音频片段,您需要设置音频源。看一下关于音频的官方教程:http://unity3d.com/learn/tutorials/modules/beginner/audio/audio-sources-and-listeners
同时仔细检查相机(或场景中的某个物体)是否有audiolistener组件。