void Update() { if (skeletonAnimation == null) { return; } if (model == null) { return; } if (skeletonAnimation.skeleton.FlipX != model.facingLeft) // Detect changes in model.facingLeft { Turn(model.facingLeft); } // Detect changes in model.state var currentModelState = model.state; if (previousViewState != currentModelState) { PlayNewStableAnimation(); } previousViewState = currentModelState; }
IEnumerator JumpRoutine() { if (state == SpineBeginnerBodyState.Jumping) { yield break; // Don't jump when already jumping. } state = SpineBeginnerBodyState.Jumping; // Terribly-coded Fake jumping. { var pos = transform.localPosition; const float jumpTime = 1.2f; const float half = jumpTime * 0.5f; const float jumpPower = 20f; for (float t = 0; t < half; t += Time.deltaTime) { float d = jumpPower * (half - t); transform.Translate((d * Time.deltaTime) * Vector3.up); yield return(null); } for (float t = 0; t < half; t += Time.deltaTime) { float d = jumpPower * t; transform.Translate((d * Time.deltaTime) * Vector3.down); yield return(null); } transform.localPosition = pos; } state = SpineBeginnerBodyState.Idle; }
IEnumerator JumpRoutine () { if (state == SpineBeginnerBodyState.Jumping) yield break; // Don't jump when already jumping. state = SpineBeginnerBodyState.Jumping; // Terribly-coded Fake jumping. { var pos = transform.localPosition; const float jumpTime = 1.2f; const float half = jumpTime * 0.5f; const float jumpPower = 20f; for (float t = 0; t < half; t += Time.deltaTime) { float d = jumpPower * (half - t); transform.Translate((d * Time.deltaTime) * Vector3.up); yield return null; } for (float t = 0; t < half; t += Time.deltaTime) { float d = jumpPower * t; transform.Translate((d * Time.deltaTime) * Vector3.down); yield return null; } transform.localPosition = pos; } state = SpineBeginnerBodyState.Idle; }
IEnumerator JumpRoutine() { if (state == SpineBeginnerBodyState.Jumping) yield break; // Don't jump when already jumping. // Fake jumping. state = SpineBeginnerBodyState.Jumping; yield return new WaitForSeconds(1.2f); state = SpineBeginnerBodyState.Idle; }
IEnumerator JumpRoutine() { if (state == SpineBeginnerBodyState.Jumping) { yield break; // Don't jump when already jumping. } // Fake jumping. state = SpineBeginnerBodyState.Jumping; yield return(new WaitForSeconds(1.2f)); state = SpineBeginnerBodyState.Idle; }
public void TryMove(float speed) { currentSpeed = speed; // show the "speed" in the Inspector. if (speed != 0) { bool speedIsNegative = (speed < 0f); facingLeft = speedIsNegative; // Change facing direction whenever speed is not 0. } if (state != SpineBeginnerBodyState.Jumping) { state = (speed == 0) ? SpineBeginnerBodyState.Idle : SpineBeginnerBodyState.Running; } }
private void Update() { if ((this.skeletonAnimation != null) && (this.model != null)) { if (this.skeletonAnimation.skeleton.FlipX != this.model.facingLeft) { this.Turn(this.model.facingLeft); } SpineBeginnerBodyState state = this.model.state; if (this.previousViewState != state) { this.PlayNewStableAnimation(); } this.previousViewState = state; } }
void Update () { if (skeletonAnimation == null) return; if (model == null) return; if (skeletonAnimation.skeleton.FlipX != model.facingLeft) { // Detect changes in model.facingLeft Turn(model.facingLeft); } // Detect changes in model.state var currentModelState = model.state; if (previousViewState != currentModelState) { PlayNewStableAnimation(); } previousViewState = currentModelState; }
private void PlayNewStableAnimation() { Spine.Animation jump; SpineBeginnerBodyState state = this.model.state; if ((this.previousViewState == SpineBeginnerBodyState.Jumping) && (state != SpineBeginnerBodyState.Jumping)) { this.PlayFootstepSound(); } if (state == SpineBeginnerBodyState.Jumping) { this.jumpSource.Play(); jump = (Spine.Animation) this.jump; } else if (state == SpineBeginnerBodyState.Running) { jump = (Spine.Animation) this.run; } else { jump = (Spine.Animation) this.idle; } this.skeletonAnimation.AnimationState.SetAnimation(0, jump, true); }