Animation Pauses

This commit is contained in:
Syntriax 2022-02-26 20:00:03 +03:00
parent caab797e6d
commit 5444ba8f1c
4 changed files with 29 additions and 6 deletions

View File

@ -11,6 +11,7 @@ namespace AI
protected IMovement movement = null; protected IMovement movement = null;
protected SpriteRenderer spriteRenderer = null; protected SpriteRenderer spriteRenderer = null;
protected Animator animator = null;
protected CollisionChecker leftWallChecker = null; protected CollisionChecker leftWallChecker = null;
protected CollisionChecker rightWallChecker = null; protected CollisionChecker rightWallChecker = null;
@ -19,8 +20,16 @@ namespace AI
#region IPausable #region IPausable
public bool IsPaused { get; protected set; } = false; public bool IsPaused { get; protected set; } = false;
public virtual void Pause() => IsPaused = true; public virtual void Pause()
public virtual void Resume() => IsPaused = false; {
IsPaused = true;
animator.enabled = !IsPaused;
}
public virtual void Resume()
{
IsPaused = false;
animator.enabled = !IsPaused;
}
#endregion #endregion
@ -35,6 +44,8 @@ namespace AI
{ {
movement = gameObject.AddComponent<EnemyMovement>(); movement = gameObject.AddComponent<EnemyMovement>();
spriteRenderer = gameObject.GetComponent<SpriteRenderer>(); spriteRenderer = gameObject.GetComponent<SpriteRenderer>();
animator = gameObject.GetComponent<Animator>();
leftWallChecker = GetCollisionCheckerOnChild("Collision Checkers/Left Wall"); leftWallChecker = GetCollisionCheckerOnChild("Collision Checkers/Left Wall");
rightWallChecker = GetCollisionCheckerOnChild("Collision Checkers/Right Wall"); rightWallChecker = GetCollisionCheckerOnChild("Collision Checkers/Right Wall");
leftGroundChecker = GetCollisionCheckerOnChild("Collision Checkers/Left Ground"); leftGroundChecker = GetCollisionCheckerOnChild("Collision Checkers/Left Ground");

View File

@ -8,11 +8,13 @@ namespace AI
{ {
public Rigidbody2D Rigidbody { get; private set; } = null; public Rigidbody2D Rigidbody { get; private set; } = null;
private AudioSource audioSource = null; private AudioSource audioSource = null;
private Animator animator = null;
private void Awake() private void Awake()
{ {
Rigidbody = GetComponent<Rigidbody2D>(); Rigidbody = GetComponent<Rigidbody2D>();
audioSource = GetComponent<AudioSource>(); audioSource = GetComponent<AudioSource>();
animator = GetComponent<Animator>();
} }
public void SetVelocity(Vector2 velocity) public void SetVelocity(Vector2 velocity)
@ -34,17 +36,18 @@ namespace AI
public void Pause() public void Pause()
{ {
IsPaused = true; IsPaused = true;
UpdateRigidbody(); UpdateComponents();
} }
public void Resume() public void Resume()
{ {
IsPaused = false; IsPaused = false;
UpdateRigidbody(); UpdateComponents();
} }
private void UpdateRigidbody() private void UpdateComponents()
{ {
Rigidbody.simulated = !IsPaused; Rigidbody.simulated = !IsPaused;
animator.enabled = !IsPaused;
} }
} }
} }

View File

@ -51,6 +51,9 @@ namespace AI
protected virtual void Update() protected virtual void Update()
{ {
if (IsPaused)
return;
remainingCooldown -= Time.deltaTime; remainingCooldown -= Time.deltaTime;
if (canShoot && !isShooting) if (canShoot && !isShooting)

View File

@ -162,13 +162,19 @@ namespace Player
public void Pause() public void Pause()
{ {
IsPaused = true; IsPaused = true;
_playerRigidbody2D.simulated = !IsPaused; UpdateComponents();
} }
public void Resume() public void Resume()
{ {
IsPaused = false; IsPaused = false;
UpdateComponents();
}
private void UpdateComponents()
{
_playerRigidbody2D.simulated = !IsPaused; _playerRigidbody2D.simulated = !IsPaused;
animator.enabled = !IsPaused;
} }
// MOVE METHODS // MOVE METHODS