Example #1
0
    private void Update()
    {
        if (!isMovementAllowed)
        {
            return;
        }

        //Get input
        if (!gameOver.activeSelf)
        {
            float moveVertical   = Input.GetAxisRaw("Vertical");
            float moveHorizontal = Input.GetAxisRaw("Horizontal");

            //Calculations
            direction           = new Vector3(moveHorizontal, 0.0f, moveVertical);
            normalizedDirection = direction.normalized * directionMultiplier;
            float targetAngle = Mathf.Atan2(normalizedDirection.x, normalizedDirection.z) * Mathf.Rad2Deg;
            moveDirection = Quaternion.Euler(0.0f, targetAngle, 0.0f) * Vector3.forward;
            bool isRangeInvoked = dungeonPlayerRange ? dungeonPlayerRange.GetIsInvoking() : false;
            bool isMeleeInvoked = dungeonPlayerMelee ? dungeonPlayerMelee.GetIsInvoking() : false;
            if (!isRangeInvoked && !isMeleeInvoked)
            {
                this.SetIsInvoking(true);

                if (direction == Vector3.zero)
                {
                    OnPlayerMove?.Invoke(moveDirection.normalized, 0.0f, 0.0f, false);
                }
                else
                {
                    if (canRun && Input.GetKey(KeyCode.LeftShift))
                    {
                        OnPlayerMove?.Invoke(moveDirection.normalized, runSpeed, 1.0f, true);
                    }
                    else
                    {
                        OnPlayerMove?.Invoke(moveDirection.normalized, walkSpeed, 0.5f, true);
                    }
                }

                if (direction != Vector3.zero)
                {
                    OnPlayerRotate?.Invoke(normalizedDirection, turnSpeed);
                }
            }
            else
            {
                this.SetIsInvoking(false);
            }
        }
        else
        {
            gameOverBool = true;
            this.DisableMovement();
        }
    }
Example #2
0
 public void RotatePlayer(Quaternion rotation)
 {
     OnPlayerRotate?.Invoke(rotation);
 }