Ejemplo n.º 1
0
 private void Start()
 {
     _spriteRenderer     = GetComponent <SpriteRenderer>();
     _walkDownAnimation  = new SpriteAnimator(_walkDownSprites, _spriteRenderer);
     _walkLeftAnimation  = new SpriteAnimator(_walkLeftSprites, _spriteRenderer);
     _walkRightAnimation = new SpriteAnimator(_walkRightSprites, _spriteRenderer);
     _walkUpAnimation    = new SpriteAnimator(_walkUpSprites, _spriteRenderer);
     SetDirection(_defaultDirection);
     _currentAnimation = _walkDownAnimation;
 }
Ejemplo n.º 2
0
        private void Update()
        {
            SpriteAnimator prevAnimation = _currentAnimation;

            if (MoveY == -1)
            {
                _currentAnimation = _walkDownAnimation;
            }
            else if (MoveY == 1)
            {
                _currentAnimation = _walkUpAnimation;
            }
            else if (MoveX == -1)
            {
                _currentAnimation = _walkLeftAnimation;
            }
            else if (MoveX == 1)
            {
                _currentAnimation = _walkRightAnimation;
            }

            if (_currentAnimation != prevAnimation || IsMoving != _wasMoving)
            {
                _currentAnimation.Reset();
            }

            if (IsMoving)
            {
                _currentAnimation.PlayAnimation();
            }
            else
            {
                _spriteRenderer.sprite = _currentAnimation.Frames[0];
            }

            _wasMoving = IsMoving;
        }