protected void ChangeState(GolemStates _newState) { lastState = actualState; actualState = _newState; }
protected IEnumerator ChangeStateWhenAnimationIsOver(string _actualAnimationName, GolemStates _stateToChange) { while (!animator.GetCurrentAnimatorStateInfo(0).IsName(_actualAnimationName)) { yield return(null); } while (animator.GetCurrentAnimatorStateInfo(0).IsName(_actualAnimationName)) { yield return(null); } ChangeState(_stateToChange); }
private void Update() { Vector2 golemVector = golemPath.desiredVelocity.normalized; if (!isAttacking) { // This is for shooting enemy so he faces where the player is if (gameObject.name == "shooting enemy (Clone)" && GetComponent <ShootingEnemy>().isShoot) { Vector2 direction = player.transform.position - this.transform.position; direction = direction.normalized; if (direction.x <= -animationChangeRange) { anim.ChangeAnimationState(golem_Left); movDirection = GolemStates.left; } else if (direction.x > animationChangeRange) { anim.ChangeAnimationState(golem_Right); movDirection = GolemStates.right; } if (direction.y > animationChangeRange) { anim.ChangeAnimationState(golem_Up); movDirection = GolemStates.up; } else if (direction.y <= -animationChangeRange) { anim.ChangeAnimationState(golem_Down); movDirection = GolemStates.down; } } else { if (golemVector.x <= -animationChangeRange) { anim.ChangeAnimationState(golem_Left); movDirection = GolemStates.left; } else if (golemVector.x > animationChangeRange) { anim.ChangeAnimationState(golem_Right); movDirection = GolemStates.right; } if (golemVector.y > animationChangeRange) { anim.ChangeAnimationState(golem_Up); movDirection = GolemStates.up; } else if (golemVector.y <= -animationChangeRange) { anim.ChangeAnimationState(golem_Down); movDirection = GolemStates.down; } } } //Debug.Log(golemPath.desiredVelocity); // Debug.Log(Vector2.Distance(this.gameObject.transform.position, player.gameObject.transform.position)); //attack animations if (Vector2.Distance(this.gameObject.transform.position, player.gameObject.transform.position) <= attackRange && gameObject.name != "shooting enemy (Clone))") { switch (movDirection) { case GolemStates.up: anim.ChangeAnimationState(attack_up); isAttacking = true; break; case GolemStates.down: anim.ChangeAnimationState(attack_down); isAttacking = true; break; case GolemStates.left: anim.ChangeAnimationState(attack_left); isAttacking = true; break; case GolemStates.right: anim.ChangeAnimationState(attack_right); isAttacking = true; break; } } else { isAttacking = false; } }