So i am making a game and i am trying to make footsteps work but i cant make it work because i do not know what to write exactly.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public float speed;
private float Move;
public Animator animator;
public float jump;
public bool isJumping;
private Rigidbody2D rb;
AudioSource audioSrc;
[SerializeField] private AudioSource jumpSoundEffect;
[SerializeField] private AudioSource WalkingSoundEffect;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update()
{
[B] if (HorizontalSpeed > 0.01)
{
WalkingSoundEffect.Play();
}
else
{
WalkingSoundEffect.Stop();
}[/B]
Move = Input.GetAxis("Horizontal");
rb.velocity = new Vector2(speed * Move, rb.velocity.y);
animator.SetFloat("Speed", Mathf.Abs(Move));
if (Input.GetButtonDown("Jump") && isJumping == false)
{
rb.AddForce(new Vector2(rb.velocity.x, jump));
Debug.Log("jump");
}
if (Move > 0)
{
gameObject.transform.localScale = new Vector3(0.1717f,0.1717f,0.1717f);
}
if (Move < 0)
{
gameObject.transform.localScale = new Vector3(-0.1717f,0.1717f,0.1717f);
}
}
private void OnCollisionEnter2D(Collision2D other)
{
if(other.gameObject.CompareTag("Ground"))
{
isJumping = false;
}
}
private void OnCollisionExit2D(Collision2D other)
{
if(other.gameObject.CompareTag("Ground"))
{
jumpSoundEffect.Play();
isJumping = true;
}
}
}
This is my code and the code that is bold is what i need help with because i do not know how to incorporate it.