示例#1
0
    // Update is called once per frame
    private void Update()
    {
        bool moved = false;

        if ((Mathf.Abs(Input.GetAxis("Horizontal")) != 0 || Mathf.Abs(Input.GetAxis("Vertical")) != 0) && _isMobile)
        {
            _animator.MovePlayer();
            Move();
            moved = true;
        }
        else
        {
            _animator.StopPlayer();
        }

        if (Input.GetAxis("Jump") == 1.0f && _currentTimeOnGround > JumpDelay && _isMobile)
        {
            _isGrounded = false;
            Jump();
        }

        // Checking for blocks the player is standing on
        if (moved && _isGrounded || !_isGrounded)
        {
            foreach (BlockBehaviour block in _blockList)
            {
                block.SetIsPlayerStandingOn(false);
            }
            _blockList = new List <BlockBehaviour>();
        }

        if (_rb.velocity.y < 0 || moved && _isGrounded)
        {
            CheckOnGround();
        }

        //
        if (_isGrounded)
        {
            _currentTimeInAir     = 0;
            _currentTimeOnGround += Time.deltaTime;
        }
        else
        {
            _currentTimeOnGround = 0;
            _currentTimeInAir   += Time.deltaTime;
        }

        //reload game
        if (_currentTimeInAir > ResetDelay)
        {
            _currentTimeInAir = 0;
            // let's not do this
            // SceneController.Instance.ReloadCurrentScene();
        }
    }
示例#2
0
    // Update is called once per frame
    private void Update()
    {
        bool moved = false;

        if ((Mathf.Abs(Input.GetAxis("Horizontal")) != 0 || Mathf.Abs(Input.GetAxis("Vertical")) != 0) && _isMobile)
        {
            _animator.MovePlayer();
            Move();
            moved = true;
        }
        else
        {
            _animator.StopPlayer();
        }

        if (Input.GetAxis("Jump") == 1.0f && _currentDelay > JumpDelay && _isMobile)
        {
            _isGrounded = false;
            Jump();
        }

        // Checking for blocks the player is standing on
        if (moved && _isGrounded || !_isGrounded)
        {
            foreach (BlockBehaviour block in _blockList)
            {
                block.SetIsPlayerStandingOn(false);
            }
            _blockList = new List <BlockBehaviour>();
        }

        if (_rb.velocity.y < 0 || moved && _isGrounded)
        {
            CheckOnGround();
        }

        if (_isGrounded)
        {
            _currentDelay += Time.deltaTime;
        }
        else
        {
            _currentDelay = 0;
        }
    }
示例#3
0
    // Update is called once per frame
    private void Update()
    {
        if ((Mathf.Abs(Input.GetAxis("Horizontal")) != 0 || Mathf.Abs(Input.GetAxis("Vertical")) != 0) && _isMobile)
        {
            _animator.MovePlayer();
            Move();
        }
        else
        {
            _animator.StopPlayer();
        }

        if (Input.GetAxis("Jump") == 1.0f && IsOnGround() && _isMobile)
        {
            Jump();
        }

        // Checking for blocks the player is standing on
        foreach (BlockBehaviour block in _blockList)
        {
            block.SetIsPlayerStandingOn(false);
        }

        _blockList = new List <BlockBehaviour>();

        for (int i = 0; i < 40; i++)
        {
            RaycastHit hit;
            Debug.DrawRay(_boxCollider.bounds.center + _groundSkinVertices[i], Vector3.down);
            if (Physics.Raycast(_boxCollider.bounds.center + _groundSkinVertices[i], Vector3.down, out hit))
            {
                BlockBehaviour     hitBlock     = hit.collider.GetComponent <BlockBehaviour>();
                BlockFaceBehaviour hitBlockFace = hit.collider.GetComponent <BlockFaceBehaviour>();
                if (hitBlock != null && hit.normal == Vector3.up && !hitBlockFace.FireRaycastFromFace(0.1f, Layer, BlockFace.Top))
                {
                    hitBlock.SetIsPlayerStandingOn(true);

                    if (!_blockList.Contains(hitBlock))
                    {
                        _blockList.Add(hitBlock);
                    }
                }
            }
        }
    }