private void Update() { if (_animator == null) { _animator = GetComponent <SpriterDotNetUnity.SpriterDotNetBehaviour>().Animator; _animator.Play(GetAnimation(1)); } if (_canMove) { if (Time.time - _timer > _landingDuration && _timer != 0.0f) { _animator.Play(GetAnimation(2)); GetComponent <AudioSource>().Play(); _timer = 0.0f; } _offset = _movingRight ? _GOBox.bounds.max.x : _GOBox.bounds.min.x; _origin = _GOBox.bounds.center; _hit = Physics2D.Raycast(new Vector2(_offset, _origin.y), _direction, _distance); Debug.DrawRay(new Vector2(_offset, _origin.y), new Vector3(_direction.x * _distance, _direction.y * _distance, 0.0f), Color.green); if (Mathf.Abs(_body.velocity.x) <= 1.0f) { _movingRight = _movingRight ? false : true; _walkingSpeed *= -1.0f; _direction.x *= -1.0f; } if (_hit.collider == null) { _movingRight = _movingRight ? false : true; _walkingSpeed *= -1.0f; _direction.x *= -1.0f; } else { _body.MoveRotation(0.0f); } } }
private void Update() { // Keep looking for the animator component unit it is found. if (_animator == null) { _animator = GetComponent <SpriterDotNetBehaviour>().Animator; if (_activated) { Activate(); } } // If a player has reached a new checkpoint, reset the old checkpoint to a ready state (not a checked state) if (_activated && _GM.SOSaveHandler.CheckpointID != ID) { _activated = false; _animator.Play(GetAnimation(-1)); } }
public void Play(int index) { _currentIndex = index; _spriterAnimator.Play(_animationList[_currentIndex]); if (index == 1) { GetComponent <AudioSource>().Play(); } }
void SetAnimation(string animaitonName) { if (currentPlayingAnimation != animaitonName) { uAnimator.Play(animaitonName); currentPlayingAnimation = animaitonName; if (_state.Equals(_State.TRANSITION_BACK)) { uAnimator.Time = uAnimator.Length; } } }
private void SwitchAnimation(int offset) { animator.Play(GetAnimation(animator, offset)); }
void Update() { if (Ember == null) { foreach (Transform child in transform) { if (child.name == "Ember") { Ember = child.gameObject; break; } } } if (anim == null) { anim = Ember.GetComponent <SpriterDotNetBehaviour>().Animator; //This event is fired whenever an animation ends. anim.AnimationFinished += animationTransitions; } if (Input.anyKeyDown) { //Advance the animation. if (anim.CurrentAnimation.Name == "Statue") { anim.Play("Statue to Idle"); } else if (anim.CurrentAnimation.Name == "Idle") { switch (mode) { case animationMode.move: anim.Play("Idle to Walk"); mode = animationMode.straightJump; break; case animationMode.straightJump: anim.Play("Begin Straight Jump"); mode = animationMode.rollingJump; break; case animationMode.rollingJump: anim.Play("Begin Rolling Jump"); mode = animationMode.lookUp; break; case animationMode.lookUp: if (!slash) { anim.Play("Grounded Forward Slash"); slash = true; } else { slash = false; anim.Play("Idle to Lookup"); mode = animationMode.lookDown; } break; case animationMode.lookDown: anim.Play("Idle to Crouch"); mode = animationMode.move; break; } } else if (anim.CurrentAnimation.Name == "Walk") { anim.Play("Run"); } else if (anim.CurrentAnimation.Name == "Run") { anim.Play("Idle"); } else if (anim.CurrentAnimation.Name == "Straight Jump Rising") { if (!slash) { anim.Play("Airborn Upward Slash"); slash = true; } else { anim.Play("Straight Jump Crest"); slash = false; } } else if (anim.CurrentAnimation.Name == "Straight Jump Falling" || anim.CurrentAnimation.Name == "Rolling Jump") { if (!slash) { if (anim.CurrentAnimation.Name == "Straight Jump Falling") { anim.Play("Airborn Forward Slash"); } else { anim.Play("Airborn Downward Slash"); } slash = true; } else { anim.Play("Straight Jump Landing"); slash = false; } } else if (anim.CurrentAnimation.Name == "Crouch") { anim.Play("Crouch to Idle"); } else if (anim.CurrentAnimation.Name == "Lookup") { if (!slash) { anim.Play("Grounded Upward Slash"); slash = true; } else { anim.Play("Lookup to Idle"); slash = false; } } } }
public void Play(int index) { _currentIndex = index; _spriterAnimator.Play(_animationList[_currentIndex]); }
private void Play(int index) { _spriterAnimator.Play(_animationList[index]); }
void HandleInput() { //determine if on the ground (using coyote time) bool trueGrounded; trueGrounded = Physics2D.Linecast(transform.position + new Vector3(currentBoxCollider.offset.x, currentBoxCollider.offset.y, 0), transform.position + new Vector3(transform.localScale.x * (currentBoxCollider.offset.x), -groundedProjection, 0), 1 << LayerMask.NameToLayer("Ground")); trueGrounded |= Physics2D.Linecast(transform.position + new Vector3(currentBoxCollider.offset.x, currentBoxCollider.offset.y, 0), transform.position + new Vector3(transform.localScale.x * (currentBoxCollider.offset.x + currentBoxCollider.size.x / 2.1f), -groundedProjection, 0), 1 << LayerMask.NameToLayer("Ground")); trueGrounded |= Physics2D.Linecast(transform.position + new Vector3(currentBoxCollider.offset.x, currentBoxCollider.offset.y, 0), transform.position + new Vector3(transform.localScale.x * (currentBoxCollider.offset.x - currentBoxCollider.size.x / 2.1f), -groundedProjection, 0), 1 << LayerMask.NameToLayer("Ground")); if (trueGrounded) { grounded = true; } else { StartCoroutine(SetGroundedWithDelay(false, 0.1f)); //coyote physics: 100ms } //determine wall hugging wallHugged = Physics2D.Linecast(transform.position + new Vector3(currentBoxCollider.offset.x, currentBoxCollider.offset.y, 0), transform.position + new Vector3(transform.localScale.x * (currentBoxCollider.offset.x + currentBoxCollider.size.x / 2 + groundedProjection), currentBoxCollider.size.y * 0.05f, 0), 1 << LayerMask.NameToLayer("Ground")); wallHugged &= Physics2D.Linecast(transform.position + new Vector3(currentBoxCollider.offset.x, currentBoxCollider.offset.y, 0), transform.position + new Vector3(transform.localScale.x * (currentBoxCollider.offset.x + currentBoxCollider.size.x / 2 + groundedProjection), currentBoxCollider.size.y * 0.5f, 0), 1 << LayerMask.NameToLayer("Ground")); wallHugged &= Physics2D.Linecast(transform.position + new Vector3(currentBoxCollider.offset.x, currentBoxCollider.offset.y, 0), transform.position + new Vector3(transform.localScale.x * (currentBoxCollider.offset.x + currentBoxCollider.size.x / 2 + groundedProjection), currentBoxCollider.size.y * 0.95f, 0), 1 << LayerMask.NameToLayer("Ground")); //reset multipliers under regular conditions if (trueGrounded && !jumping) { horizontalModifier = 1f; verticalModifier = 1f; maxSpeedModifier = 1f; } //get inputs verticalInput = GamePad.GetAxis(CAxis.LY); horizontalInput = GamePad.GetAxis(CAxis.LX); //determine vertical input if (Mathf.Abs(verticalInput) < deadZone) //no input { verticalInput = 0f; //handle stop crouching if (animator.CurrentAnimation.Name == "Crouch") { animator.Play("Crouch to Idle"); } } else //yes input { if (verticalInput < 0) //looking up { if (grounded && animator.CurrentAnimation.Name == "Idle" && Mathf.Abs(horizontalInput) < deadZone) { animator.Play("Idle to Lookup"); } } else //crouching down //from rolling jump to crouch { if (grounded && animator.CurrentAnimation.Name == "Rolling Jump") { animator.Play("Crouch"); } else if (grounded && Mathf.Abs(rigidBody.velocity.y) > 0.0001f) //explicitly don't check for animation here; "Straight Jump Landing" passes through here for some reason { animator.Play("Rolling Jump"); } //if not already crouching else if (grounded && animator.CurrentAnimation.Name != "Crouch" && animator.CurrentAnimation.Name != "Idle to Crouch") { animator.Play("Idle to Crouch"); } } } //determine if walking if (Mathf.Abs(horizontalInput) < deadZone) //no input //reset multipliers under regular conditions { if (grounded && !jumping) { dashModifier = 1f; if (animator.CurrentAnimation.Name == "Run") { animator.Play("Walk"); } } if (dashLatch) { //capture the time of last release for dashing dashTime = Time.time; dashLatch = false; } //stop walking horizontalInput = 0f; if (animator.CurrentAnimation.Name == "Walk") { //animator.Play("Walk to Idle"); //TODO: enable this animator.Play("Idle"); //TODO: remove this (why?) } } else //yes input { if (animator.CurrentAnimation.Name == "Crouch") { //TODO: slides/rolls horizontalInput = horizontalInput > 0 ? 0.0001f : -0.0001f; //TMP } else if (animator.CurrentAnimation.Name == "Lookup") { animator.Play("Lookup to Idle"); } else if (wallHugged && !grounded && (animator.CurrentAnimation.Name != "Brace on Wall" && animator.CurrentAnimation.Name != "Wall Slide" && animator.CurrentAnimation.Name != "Wall Kick")) { animator.Play("Brace on Wall"); } else { //check if dashing if (Time.time - dashTime < 0.2f && SameSign(horizontalInput, dashValue) && grounded && !dashLatch) { dashModifier = dashMultiplier; horizontalInput = maxSpeed * dashModifier * (horizontalInput > 0 ? 1 : -1); animator.Play("Run"); StartCoroutine(BuildingFriction("Run", 0.05f)); } //capture the value for dashing dashValue = horizontalInput; //BUGFIX dashLatch = true; } //BUGFIX: landing into a run if (animator.CurrentAnimation.Name == "Idle" && dashModifier != 1f) { animator.Play("Run"); StartCoroutine(BuildingFriction("Run", 0.05f)); } //start walking if (animator.CurrentAnimation.Name == "Idle") { animator.Play("Idle to Walk"); } //flip direction if (Time.timeScale > 0f) { prevLocalScaleX = transform.localScale.x; transform.localScale = new Vector3(horizontalInput > 0 ? 1 : -1, 1, 1); //play turning animations if (prevLocalScaleX != transform.localScale.x) { if (animator.CurrentAnimation.Name == "Idle" || animator.CurrentAnimation.Name == "Idle to Walk" || animator.CurrentAnimation.Name == "Walk" || animator.CurrentAnimation.Name == "Lookup to Idle") { animator.Play("Ground Turn"); } if (animator.CurrentAnimation.Name == "Straight Jump Rising" || animator.CurrentAnimation.Name == "Straight Jump Crest" || animator.CurrentAnimation.Name == "Straight Jump Falling") { animator.Play("Straight Jump Turn"); } if (animator.CurrentAnimation.Name == "Rolling Jump") { animator.Play("Rolling Jump Turn"); } } } } //determine if jumping if (GamePad.GetState().Pressed(CButton.A) && grounded) { jumping = true; maxSpeedModifier = jumpMaxSpeedMultiplier; if (animator.CurrentAnimation.Name == "Crouch") { animator.Play("Rolling Jump"); } else if (Mathf.Abs(horizontalInput) < deadZone) { animator.Play("Begin Straight Jump"); horizontalModifier = straightJumpHorizontalMultiplier; verticalModifier = straightJumpVerticalMultiplier; } else { animator.Play("Begin Rolling Jump"); //horizontalModifier = rollingJumpHorizontalMultiplier; //verticalModifier = rollingJumpVerticalMultiplier; } } if (GamePad.GetState().Pressed(CButton.A) && !grounded && wallHugged && (animator.CurrentAnimation.Name == "Brace on Wall" || animator.CurrentAnimation.Name == "Wall Slide")) { wallJumping = true; maxSpeedModifier = jumpMaxSpeedMultiplier; animator.Play("Wall Kick"); } //determine if attacking on the ground if (GamePad.GetState().Pressed(CButton.B) && grounded) { if (verticalInput < -deadZone) //yes up input { if (animator.CurrentAnimation.Name == "Run") { animator.Play("Grounded Upward Slash"); //TODO: replace with "Running Upward Slash" } else { animator.Play("Grounded Upward Slash"); } StartCoroutine(EnableDamagerForPeriod(0, 0.3f)); } else //no vertical input { if (animator.CurrentAnimation.Name == "Run") { animator.Play("Grounded Forward Slash"); //TODO: replace with "Running Forward Slash" } else { animator.Play("Grounded Forward Slash"); } StartCoroutine(EnableDamagerForPeriod(1, 0.3f)); } } //determine if attacking in the air if (GamePad.GetState().Pressed(CButton.B) && !grounded) { if (verticalInput < -deadZone) //yes up input { animator.Play("Airborn Upward Slash"); StartCoroutine(EnableDamagerForPeriod(0, 0.3f)); } else if (verticalInput > deadZone) //yes down input { animator.Play("Airborn Downward Slash"); StartCoroutine(EnableDamagerForPeriod(2, 0.3f)); } else //no vertical input { animator.Play("Airborn Forward Slash"); StartCoroutine(EnableDamagerForPeriod(1, 0.3f)); } } //determine if releasing the attack button if (GamePad.GetState().Released(CButton.B)) { foreach (DamagerController dmgr in damagerControllers) { dmgr.gameObject.SetActive(false); } } //BUGFIX: prevent crouch-gliding and slash-gliding if (grounded && (animator.CurrentAnimation.Name == "Crouch")) { horizontalInput = 0f; dashModifier = 1f; } //BUGFIX: falling animations after walking/running off a cliff if (rigidBody.velocity.y < -0.0001f && (animator.CurrentAnimation.Name == "Walk" || animator.CurrentAnimation.Name == "Run")) { animator.Play("Straight Jump Falling"); } }