Search Unity

Help with Joystick UI and Audio

Discussion in 'Scripting' started by Ezequiel75, Feb 14, 2020.

  1. Ezequiel75

    Ezequiel75

    Joined:
    Sep 9, 2018
    Posts:
    4
    Good, I tell you I have a game scene, and well, in that scene I have my first-person controller, already with the touch controls (the game is for android). I wanted to make my character have sounds when walking, and well, since I don't know much, I couldn't make a system of programming steps, and I decided to try to make things easier. And I simply made my sound of steps (sound in Arena, which is in an empty gameobject) is played only when I press the joystick and it pauses, when I stop pressing it.

    (I did that with the functions of Button Down and Button Up)

    It works well and has given me a good result, but here comes my problem.

    The object of the game with the sound of the steps must be deactivated until the player goes through an activator that activates it.

    I also did that, and it works, but there is a small error in that, when I go through the trigger by holding the joystick, to advance continuously, the sound of steps does not play until I stop pressing the joystick and press it again, and it is bad, if the player advances continuously the sound will not be heard when you press the joystick without releasing it, until you release it and press it again.

    Is there any way to correct this? I would like the sound to not depend on releasing and pressing the joystick again to play.
     
  2. wileyjerkins

    wileyjerkins

    Joined:
    Oct 13, 2017
    Posts:
    58
    Create a separate invisible sound controller object and in its fixed update have its position match the player position. That object is always active and invisible and plays every sound that is near the player. Also, consider using something similar to Input.GetKey which could run a sound as long as an input is active. That is better than button down and button up for you I think because you won't have to keep track of the toggled state.
    https://docs.unity3d.com/ScriptReference/Input.GetKey.html
     
unityunity