Quantcast
Channel: Answers for "Footsteps?"
Viewing all articles
Browse latest Browse all 8

Answer by aldonaletto

$
0
0
You can't use *yield* inside Update or any other periodic routine (LateUpdate, FixedUpdate, OnGUI), but a very similar approach can work if started at Start (yes, Start can use *yield*!):
var footsteps : AudioClip;
var waitTime = 0.5;

function Start () {
  // create an infinite loop that runs every frame:
  while (true){
    if (Mathf.Abs(Input.GetAxis("Vertical")) > 0.1){
      yield WaitForSeconds(waitTime);
      audio.Play(footsteps);
    }
    yield; // let Unity free till next frame
  }
}
This implements a kind of private Update: the code inside the *while* infinite loop is executed every frame, then the yield instruction lets Unity free to take care of its business until next frame.

Viewing all articles
Browse latest Browse all 8

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>