i wonder if someone can help me?Ii have movement/sound script in my FPS connected to my player the idea is that he should have a footstep sound for moving fowerd & back and left & right however my audo only plays when the player moves fowed can anyone hlep me with this? here is what I have so far
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Movement : MonoBehaviour {
public float Speed = 2f;
public float Senctivaty = 2f;
public GameObject Eyes;
public float jumpforce = 4f;
CharacterController player;
float MoveFB, MoveLR, RotX, RotY, vertVelocity;
private bool HasJumped,isCrouched;
public AudioSource Audios;
public AudioSource Audios2;
// Use this for initialization
void Start() {
player = GetComponent<CharacterController>();
}
// Update is called once per frame
void Update()
{
MoveFB = Input.GetAxis("Vertical") * Speed;
MoveLR = Input.GetAxis("Horizontal") * Speed;
RotX = Input.GetAxis("Mouse X") * Senctivaty;
RotY = Input.GetAxis("Mouse Y") * Senctivaty;
transform.Rotate(0, RotX, 0);
Eyes.transform.Rotate(-RotY, 0, 0);
Vector3 movement = new Vector3(MoveLR, vertVelocity, MoveFB);
movement = transform.rotation * movement;
player.Move(movement * Time.deltaTime);
PlayFootsteps();
Playfootsteps2();
if (Input.GetKeyDown(KeyCode.Space))
{
HasJumped = true;
}
if (Input.GetButtonDown("Crouch"))
{
if (isCrouched == false)
{
player.height = player.height / 2;
isCrouched = true;
}
else
{
player.height = player.height * 2;
isCrouched = false;
}
}
ApplyGravty();
}
private void ApplyGravty()
{
if (player.isGrounded == true)
{
if (HasJumped == false)
{
vertVelocity = Physics.gravity.y;
}
else
{
vertVelocity = jumpforce;
}
}
else
{
vertVelocity += Physics.gravity.y * Time.deltaTime;
vertVelocity = Mathf.Clamp(vertVelocity, -50f, jumpforce);
HasJumped = false;
}
}
private void PlayFootsteps()
{
if (MoveFB > 0.1f && MoveFB < Speed + 0.1f)
{
Audios.enabled = true;
Audios.loop = true;
}
if (MoveFB < 0.1f)
{
Audios.enabled = false;
Audios.loop = false;
}
Playfootsteps2();
}
private void Playfootsteps2()
{
if (MoveLR > 0.1f && MoveLR < Speed + 0.1f)
{
Audios2.enabled = true;
Audios2.loop = true;
}
if (MoveLR < 0.1f)
{
Audios2.enabled = false;
Audios2.loop = false;
}
}
}
Thank you for your help