private void Update() { if (_isAttacking) { if (_attackDelay <= 0) { _playerHealthComponent.DecreaseHealth(damage); _attackDelay = 1f; } _attackDelay -= Time.deltaTime; return; } if (isWalking) { var a = Random.Range(-1.0f, 1.0f); _walkCounter -= Time.deltaTime; switch (_walkDirection) { case 0: _myRigidBody.velocity = new Vector2(-moveSpeed, a); _animator.Play("Move_left"); break; case 1: _myRigidBody.velocity = new Vector2(moveSpeed, a); _animator.Play("Move_right"); break; } if (!(_walkCounter < 0)) { return; } isWalking = false; _waitCounter = waitTime; switch (_walkDirection) { case 0: _animator.Play("Idle_left"); break; case 1: _animator.Play("Idle_right"); break; } } else { _waitCounter -= Time.deltaTime; _myRigidBody.velocity = Vector2.zero; if (_waitCounter < 0) { ChoseDirection(); } } }