Exemplo n.º 1
0
    void Update()
    {
        float h      = Input.GetAxis("Horizontal");
        float v      = Input.GetAxis("Vertical");
        float mouseX = Input.GetAxis("Mouse X");

        bool jumpBtn = Input.GetButtonDown("Jump");

        isBlocking = Input.GetButtonDown("Fire2");

        if (Input.GetButtonDown("Fire1"))
        {
            if (timeStamp <= Time.time)
            {
                isAttacking = true;
                timeStamp   = Time.time + 0.5f;
                weapon.Extend();
            }
        }
        else if (Input.GetButtonDown("Fire2"))
        {
            if (timeStamp <= Time.time)
            {
                isBlocking = true;
                timeStamp  = Time.time + 0.5f;
                SetShieldActive(true);
            }
        }

        moveDirection = new Vector3(h, 0f, v);
        if (moveDirection != Vector3.zero)
        {
            Quaternion targetRotation = Quaternion.LookRotation(moveDirection, Vector3.up);
            transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, 5f * Time.deltaTime);
        }

        //lookAngle += mouseX * 2f;
        //transform.rotation = Quaternion.Euler(0f, lookAngle, 0f);
        verticalSpeed -= 9.82f * Time.deltaTime;

        velocity = Mathf.Min(moveDirection.sqrMagnitude, 1f) * moveSpeed;
        movement = moveDirection * Time.deltaTime * velocity + new Vector3(0, verticalSpeed, 0);
        controller.Move(movement);
        UpdateAnimator();
    }