示例#1
0
        public void FixedUpdate()
        {
            _doJump     = Input.GetAxis("Vertical") > 0;
            _crouch     = Input.GetAxis("Vertical") < 0;
            _xAxisInput = Input.GetAxis("Horizontal");
            _contactpoller.Update();
            var walks       = Mathf.Abs(_xAxisInput) > _movingTresh;
            var newVelocity = 0f;

            if (walks && (_xAxisInput > 0 || !_contactpoller.HasLeftContact) && (_xAxisInput < 0 || !_contactpoller.HasRightContact))
            {
                newVelocity = Time.fixedDeltaTime * _walkSpeed * (_xAxisInput < 0 ? -1 : 1);
                _view._transform.localScale = (_xAxisInput < 0 ? _leftScale : _rightScale);
            }
            _view._rigidbody2D.velocity = _view._rigidbody2D.velocity.Change(x: newVelocity);

            if (_contactpoller.IsGrounded && _doJump && Mathf.Abs(_view._rigidbody2D.velocity.y) <= _jumpTresh)
            {
                _view._rigidbody2D.AddForce(Vector2.up * _jumpForce, ForceMode2D.Impulse);
            }

            if (_contactpoller.IsGrounded && _crouch)
            {
                _view._crouchCollider2D.isTrigger = true;
            }
            else
            {
                _view._crouchCollider2D.isTrigger = false;
            }

            if (_contactpoller.IsGrounded)
            {
                _spriteAnimator.StartAnimation(_view._spriteRenderer, _crouch ? AnimState.SpecialMove : walks ? AnimState.Run : AnimState.Idle, true, _animationSpeed);
            }
            else if (Mathf.Abs(_view._rigidbody2D.velocity.y) > _flyTresh)
            {
                _spriteAnimator.StartAnimation(_view._spriteRenderer, AnimState.Jump, true, _animationSpeed);
            }
        }
示例#2
0
        private void Awake()
        {
            SpriteAnimConfg eagleConfig = Resources.Load <SpriteAnimConfg>("Eagle");

            _eagleAnimator = new SpriteAnimator(eagleConfig);
            _eagleAnimator.StartAnimation(_characterViews[1]._spriteRenderer, AnimState.Idle, true, _playeranimationSpeed);
            _eagleController = new EagleMove(_characterViews[1], _eagleAnimator);
            SpriteAnimConfg foxyConfig = Resources.Load <SpriteAnimConfg>("Foxy");

            _foxyAnimator = new SpriteAnimator(foxyConfig);
            _foxyAnimator.StartAnimation(_characterViews[0]._spriteRenderer, AnimState.Idle, true, _playeranimationSpeed);
            _foxyController = new FoxyMove(_characterViews[0], _foxyAnimator);
            SpriteAnimConfg frogConfig = Resources.Load <SpriteAnimConfg>("Frog");

            _frogAnimator = new SpriteAnimator(frogConfig);
            _frogAnimator.StartAnimation(_characterViews[2]._spriteRenderer, AnimState.Idle, true, _playeranimationSpeed);
            _frogController   = new FrogMove(_characterViews[2], _wallList, _frogAnimator);
            _cameraController = new CameraController(_characterViews, _camera);
            _itemManager      = new ItemManager(_characterViews, _itemList, _inventory);
        }
示例#3
0
        public void FixedUpdate()
        {
            _yAxisInput = Input.GetAxis("Vertical");
            _xAxisInput = Input.GetAxis("Horizontal");
            var XnewVelocity = 0f;
            var YnewVelocity = 0f;

            if ((_xAxisInput > 0) || (_xAxisInput < 0))
            {
                XnewVelocity = Time.fixedDeltaTime * _flySpeed * (_xAxisInput < 0 ? -1 : 1);
                _view._transform.localScale = (_xAxisInput < 0 ? _leftScale : _rightScale);
            }
            if ((_yAxisInput > 0) || (_yAxisInput < 0))
            {
                YnewVelocity = Time.fixedDeltaTime * _flySpeed * (_yAxisInput < 0 ? -1 : 1);
            }
            _view._rigidbody2D.velocity = _view._rigidbody2D.velocity.Change(x: XnewVelocity);
            _view._rigidbody2D.velocity = _view._rigidbody2D.velocity.Change(y: YnewVelocity);

            _spriteAnimator.StartAnimation(_view._spriteRenderer, AnimState.Idle, true, _animationSpeed);
        }