- Home /
Question by
NamelessGaming · Jul 09, 2017 at 11:29 AM ·
c#unity 5beginnermonodevelopfootsteps
How to get step sound using axis.x movement
I'm a beginner at unity and I would like to know how i can fix my code, I have tried to make it as simple as possible yet it still wont work (C#)! What do i need to do? Here is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerPlatformerController : PhysicsObject {
public float maxSpeed = 7;
public float jumpTakeOffSpeed = 7;
private SpriteRenderer spriteRenderer;
private Animator animator;
// Use this for initialization
void Awake ()
{
spriteRenderer = GetComponent<SpriteRenderer> ();
animator = GetComponent<Animator> ();
}
//Update is called once per frame
protected override void ComputeVelocity()
{
Vector2 move = Vector2.zero;
move.x = Input.GetAxis ("Horizontal");
if (Input.GetButtonDown ("Jump") && grounded) {
velocity.y = jumpTakeOffSpeed;
} else if (Input.GetButtonUp ("Jump"))
{
if (velocity.y > 0)
velocity.y = velocity.y * .5f;
}
bool flipSprite = (spriteRenderer.flipX ? (move.x > 0.01f) : (move.x < 0.01f));
if (flipSprite)
{
spriteRenderer.flipX = !spriteRenderer.flipX;
}
animator.SetBool ("grounded", grounded);
animator.SetFloat ("velocityX", Mathf.Abs (velocity.x) / maxSpeed);
targetVelocity = move * maxSpeed;
***{
if (move.x != 0)
GetComponent<AudioSource> ().UnPause ();
}***
}
}
I do not receive any error messages yet it still makes no sound!
Comment
Answer by Vollmondum · Jul 09, 2017 at 11:39 AM
Just check if (grounded && (velocity.x || velocity.z) > 0). On true footsteps.Audio.Unpause(); On false Pause.