void FixedUpdate() { if (Alive()) { PlayerNearby = LookForPlayer(); if (!Patrol && !PlayerNearby && !(activeState is IdleState)) { SetState(new IdleState()); } else if (Patrol && !PlayerNearby && !(activeState is PatrolState)) { SetState(new PatrolState()); } else if (PlayerNearby && !IsPlayerReachable() && !(activeState is HideState)) { SetState(new HideState()); } else if (PlayerMeleeRange() && !(activeState is MeleeAttackState)) { SetState(new MeleeAttackState()); } else if (PlayerNearby && !PlayerMeleeRange() && IsPlayerReachable() && !(activeState is ChaseState)) { SetState(new ChaseState()); } activeState.Act(); } if (!Alive() && !triggeredDeath) { triggeredDeath = true; AgentAnimator.SetTrigger("Death"); } }
private void Jump() { if ((onGround)) //if the player presses space and we aren't already jumping or falling { onGround = false; AgentRigidbody.AddForce(new Vector2(0, jumpSpeed)); // make the player character jump (i.e apply a positive force on the y axis) AgentAnimator.SetTrigger("Jump"); // Trigger the jump animation } }
protected override void TakeDamage(int hp) { if (!Alive()) { AgentAnimator.SetTrigger("Death"); return; } base.TakeDamage(hp); Immunity = true; }