Search Unity

Audio Need help playing an audio clip

Discussion in 'Audio & Video' started by Marqmule, Feb 10, 2018.

  1. Marqmule

    Marqmule

    Joined:
    Jul 16, 2017
    Posts:
    3
    how do get a desired audio clip to play if these conditions are met? I already have a working footsteps sound effect and tried to use the same getcomponent<audiosource>.play method but no sound plays when the spacebar is pressed
    Here is my code (i know there is a better way to double jump but i figured this out alone and it works for me)

    if (controller.isGrounded)
    {
    numberOfJumps = 0;
    if (Input.GetButtonDown ("Jump") && numberOfJumps <= 1)
    {
    numberOfJumps += 1;
    moveDirection.y = jumpForce;
    GetComponent<AudioSource>().Play();
    }
    }
    if(!controller.isGrounded )
    {
    if (Input.GetButtonDown("Jump") && numberOfJumps <= 1)
    {
    numberOfJumps += 1;
    moveDirection.y = jumpForce;
    GetComponent<AudioSource>().Play();
    }
    }
     
  2. Marqmule

    Marqmule

    Joined:
    Jul 16, 2017
    Posts:
    3
    10 minutes later i solved it by adding "public AudioSource jumpSound;" and "jumpSound.Play()"