예제 #1
0
 private void Update()
 {
     if (energy <= 0f)
     {
         CameraEffects.Failure();
         enabled = false;
     }
     if (body.velocity.magnitude > .1f)
     {
         isIdle          = false;
         energy         -= body.velocity.magnitude / speed * Time.deltaTime;
         walkSoundTimer += Time.deltaTime * (body.velocity.magnitude / speed);
         if (walkSoundTimer >= .3f)
         {
             walkSoundSource.clip = RandomWalkSound(walkSounds);
             walkSoundSource.Play();
             walkSoundTimer = 0f;
         }
         animator.Play("Walk");
         sprite.flipX = body.velocity.x > 0;
     }
     else
     {
         if (walkSoundSource.isPlaying)
         {
             walkSoundSource.Stop();
         }
         walkSoundTimer = 1f;
         if (!isDamaged && !isIdle)
         {
             animator.Play("Idle");
             isIdle = true;
         }
     }
 }