hi I am trying to get a footstep sound playing when the character is moving but having no luck can anyone help, thanks:)
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour
{
public float moveSpeed = 3.0f;
public float rotateSpeed = 3.0f;
Vector3 moveDirection;
public AudioClip audioClip;
private AudioSource audioSource;
private CharacterController controller;
void Start()
{
controller = GetComponent<CharacterController>();
audioSource = GetComponent<AudioSource>();
}
void Update()
{
//Feed moveDirection with input.
moveDirection = new Vector3(0, 0, Input.GetAxis("Vertical"));
//apply rotation, should be able to do this in the moveDirection var but it's not working?...
transform.Rotate(new Vector3(0, Input.GetAxis("Horizontal") * rotateSpeed * Time.deltaTime, 0));
//Multiply it by speed.
moveDirection *= moveSpeed;
//Jumping
moveDirection = transform.TransformDirection(moveDirection);
//Making the character move
controller.Move(moveDirection * Time.deltaTime);
///////TRYING TO PLAY A FOOTSTEP SOUND HERE!!
if (controller.Move == true)
{
GetComponent<AudioSource>().Play();
}
}
void OnControllerColliderHit(ControllerColliderHit hit)
{
if (hit.gameObject.name.Contains ("Wall")) {
audioSource.PlayOneShot (audioClip, 1f);
}
}
void OnTriggerEnter(Collider hit)
{
//Debug.Log("In room");
}
void OnTriggerExit(Collider hit)
{
//Debug.Log("Leaving room");
}
}