コード例 #1
0
    private void Update()
    {
        _moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, 0);

        //ground stuff
        if (_controller.Ground())
        {
            _ground          = true;
            _extraJumps      = 0;
            _jumpDownReset   = true;
            _distanceReached = false;
            //only should execute once right when landed.
            if (!_groundOneShot)
            {
                print("aHeroHasFallen.");
                _groundOneShot = true;
            }
            print(_controller.moving);
            if (_controller.moving && !_movingEffect.isPlaying)
            {
                _movingEffect.Play();
            }
            else if (!_controller.moving)
            {
                _movingEffect.Stop();
            }
        }
        else
        {
            _ground        = false;
            _groundOneShot = false;
            _movingEffect.Stop();
        }

        //jump input
        if (Input.GetAxisRaw("Jump") != 0)
        {
            _holdingJump = true;
            _jumpDown    = false;
            if (_jumpDownReset)
            {
                _jumpDown = true;
            }
            _jumpDownReset = false;
        }
        else
        {
            _distanceReached = true;
            _realJumpForce   = 0;
            _holdingJump     = false;
            _jumpDownReset   = true;
        }

        SetJump();

        //falling stuff
        //fallImminent and falling makes sure it doesn't play more than once

        if (_ground && _controller.OnEdge() && !fallImminent && !falling && !_controller.moving)
        {
            float fallTime;
            fallTime = 0.2f;
            StartCoroutine("FallImminent", fallTime);
        }
        if (!_controller.OnEdge() && !falling && fallImminent)
        {
            StopCoroutine("FallImminent");
            fallImminent = false;
        }
    }