Hey, everyone. I am working on a Super Mario Bros. clone that I am making to learn more about Unity (I’m a noob :p). When Mario jumps, there is the jump audio clip that plays. In my script, I have it set to jump when any of the following keys: w, space, up arrow or the 8 on the keypad are pressed, but this event falls under the FixedUpdate function. When I tried to put audio.Play in there, it played, but since it is in the update function, it plays it every frame, but I only want it to play once each time you press any of the jump keys.
I am wondering if there is a way to do this through an animation. I could call the specific animation state that will play the jump audio clip from within the script when the required key is pressed. However, I don’t know if, by calling this animation state from within the update function, it will play the animation every frame.
Think of it like how the new UI in 4.6 works with an event system. You have an OnClick function that performs a function from within the attached script. It would be nice if they had this sort of system for more things than just the UI, but I don’t think they do. Correct me if there is something like this!
Is there a way to not get an event that is in the Update/FixedUpdate function to NOT be called every frame?
Thanks,
- Chris