audio script
i want to create a script that plays an audio when my player is in one specific position something like this: public FirstPersonController player; public AudioSource audio; if (player.position.y = 2.5) { audio.Play(); }
but i don't know how to do it without any compiler error.
Answer by UrielKane · Feb 25, 2018 at 07:20 PM
Why not using triggers instead of tracking player position by script? There is any good reason for that? Usually when i want a sound to be played i make sure that this event call dosent ocurr several times in one second or so, to avoid audio bugs you know. For example for the footstep system i create for my game i use the camera bobbling so when it reaches the lowest part of the cycle it trigger a coroutine call, and this coroutine make sure to play the correct footstep sound depending on the surface its touching. For the jump sound its simply a several bool checks, if is grounded and if press jump button it shoot the sound fx. And so one, so is rare to see someone trying to play a sound when the player is in a certain vector3, that doesnt make sence to me.