public void CheckDistance() { if (!target.GetComponent <Player>().isDead) { if (Vector3.Distance(target.position, transform.position) <= chaseRadius) { if (Vector3.Distance(target.position, transform.position) <= attackRadius) { //Attack state ChangeAnim(target.position - transform.position); stateMachine.ChangeState(GreyClaw_AttackState.Instance()); } else if (!isAttacking) { //Chase state stateMachine.ChangeState(GreyClaw_WalkingState.Instance()); } } else { //Idle State stateMachine.ChangeState(GreyClaw_IdleState.Instance()); } } else { //If player is dead ChangeAnim(Vector2.down); StopCoroutine("AttackCo"); } }
public static GreyClaw_IdleState Instance() { if (_instance == null) { _instance = new GreyClaw_IdleState(); } return(_instance); }
public override void ExecuteState(GreyClaw owner) { if (!owner.isAttacking) { owner.StartAttacking(); alreadyAttacked = true; if (alreadyAttacked) { alreadyAttacked = false; owner.GetFSM().ChangeState(GreyClaw_IdleState.Instance()); } } }
private void Start() { myRigidbody = GetComponent <Rigidbody2D>(); anim = GetComponent <Animator>(); anim.SetFloat("moveX", 0f); anim.SetFloat("moveY", -1f); isAttacking = false; target = GameObject.FindWithTag("Player").transform; stateMachine = new StateMachine <GreyClaw>(this); stateMachine.currentState = GreyClaw_IdleState.Instance(); }