From 5444ba8f1ccf6137725f5758f70b75abb79fff43 Mon Sep 17 00:00:00 2001 From: Syntriax Date: Sat, 26 Feb 2022 20:00:03 +0300 Subject: [PATCH] Animation Pauses --- Assets/Scripts/AI/BasicPatrollingEnemyAI.cs | 15 +++++++++++++-- Assets/Scripts/AI/Projectile.cs | 9 ++++++--- Assets/Scripts/AI/ShootingEnemyAI.cs | 3 +++ Assets/Scripts/Player/PlayerController.cs | 8 +++++++- 4 files changed, 29 insertions(+), 6 deletions(-) diff --git a/Assets/Scripts/AI/BasicPatrollingEnemyAI.cs b/Assets/Scripts/AI/BasicPatrollingEnemyAI.cs index d84711d..f38b570 100644 --- a/Assets/Scripts/AI/BasicPatrollingEnemyAI.cs +++ b/Assets/Scripts/AI/BasicPatrollingEnemyAI.cs @@ -11,6 +11,7 @@ namespace AI protected IMovement movement = null; protected SpriteRenderer spriteRenderer = null; + protected Animator animator = null; protected CollisionChecker leftWallChecker = null; protected CollisionChecker rightWallChecker = null; @@ -19,8 +20,16 @@ namespace AI #region IPausable public bool IsPaused { get; protected set; } = false; - public virtual void Pause() => IsPaused = true; - public virtual void Resume() => IsPaused = false; + public virtual void Pause() + { + IsPaused = true; + animator.enabled = !IsPaused; + } + public virtual void Resume() + { + IsPaused = false; + animator.enabled = !IsPaused; + } #endregion @@ -35,6 +44,8 @@ namespace AI { movement = gameObject.AddComponent(); spriteRenderer = gameObject.GetComponent(); + animator = gameObject.GetComponent(); + leftWallChecker = GetCollisionCheckerOnChild("Collision Checkers/Left Wall"); rightWallChecker = GetCollisionCheckerOnChild("Collision Checkers/Right Wall"); leftGroundChecker = GetCollisionCheckerOnChild("Collision Checkers/Left Ground"); diff --git a/Assets/Scripts/AI/Projectile.cs b/Assets/Scripts/AI/Projectile.cs index 02508da..871146a 100644 --- a/Assets/Scripts/AI/Projectile.cs +++ b/Assets/Scripts/AI/Projectile.cs @@ -8,11 +8,13 @@ namespace AI { public Rigidbody2D Rigidbody { get; private set; } = null; private AudioSource audioSource = null; + private Animator animator = null; private void Awake() { Rigidbody = GetComponent(); audioSource = GetComponent(); + animator = GetComponent(); } public void SetVelocity(Vector2 velocity) @@ -34,17 +36,18 @@ namespace AI public void Pause() { IsPaused = true; - UpdateRigidbody(); + UpdateComponents(); } public void Resume() { IsPaused = false; - UpdateRigidbody(); + UpdateComponents(); } - private void UpdateRigidbody() + private void UpdateComponents() { Rigidbody.simulated = !IsPaused; + animator.enabled = !IsPaused; } } } diff --git a/Assets/Scripts/AI/ShootingEnemyAI.cs b/Assets/Scripts/AI/ShootingEnemyAI.cs index b957925..733ddd4 100644 --- a/Assets/Scripts/AI/ShootingEnemyAI.cs +++ b/Assets/Scripts/AI/ShootingEnemyAI.cs @@ -51,6 +51,9 @@ namespace AI protected virtual void Update() { + if (IsPaused) + return; + remainingCooldown -= Time.deltaTime; if (canShoot && !isShooting) diff --git a/Assets/Scripts/Player/PlayerController.cs b/Assets/Scripts/Player/PlayerController.cs index 1a4aca3..192ae72 100644 --- a/Assets/Scripts/Player/PlayerController.cs +++ b/Assets/Scripts/Player/PlayerController.cs @@ -162,13 +162,19 @@ namespace Player public void Pause() { IsPaused = true; - _playerRigidbody2D.simulated = !IsPaused; + UpdateComponents(); } public void Resume() { IsPaused = false; + UpdateComponents(); + } + + private void UpdateComponents() + { _playerRigidbody2D.simulated = !IsPaused; + animator.enabled = !IsPaused; } // MOVE METHODS