Animation Pauses
This commit is contained in:
		@@ -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<EnemyMovement>();
 | 
			
		||||
            spriteRenderer = gameObject.GetComponent<SpriteRenderer>();
 | 
			
		||||
            animator = gameObject.GetComponent<Animator>();
 | 
			
		||||
 | 
			
		||||
            leftWallChecker = GetCollisionCheckerOnChild("Collision Checkers/Left Wall");
 | 
			
		||||
            rightWallChecker = GetCollisionCheckerOnChild("Collision Checkers/Right Wall");
 | 
			
		||||
            leftGroundChecker = GetCollisionCheckerOnChild("Collision Checkers/Left Ground");
 | 
			
		||||
 
 | 
			
		||||
@@ -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<Rigidbody2D>();
 | 
			
		||||
            audioSource = GetComponent<AudioSource>();
 | 
			
		||||
            animator = GetComponent<Animator>();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        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;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -51,6 +51,9 @@ namespace AI
 | 
			
		||||
 | 
			
		||||
        protected virtual void Update()
 | 
			
		||||
        {
 | 
			
		||||
            if (IsPaused)
 | 
			
		||||
                return;
 | 
			
		||||
 | 
			
		||||
            remainingCooldown -= Time.deltaTime;
 | 
			
		||||
 | 
			
		||||
            if (canShoot && !isShooting)
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user