Exemplo n.º 1
0
    //Update & StateMachine
    private void Update()
    {
        //currentState();
        //anim.SetInteger("state", (int)state);
        switch (state)
        {
        default:
        case State.Normal:
            PlayerMovement();
            normalMove();
            clutchClaw();
            checkCrouch();
            break;

        case State.Crouch:
            PlayerMovement();
            crouchMove();
            checkUnCrouch();
            break;

        case State.Clutching:
            clutchClawMove();
            break;

        case State.ClutchThrown:
            HandleThrow();
            PlayerMovement();
            normalMove();
            break;
        }

        if (!inDialogue())
        {
            dialogueOn = false;
            //dialogue
            if (inDialogueRange == true && Input.GetKeyDown(interactKey))
            {
                currentDialogue.ActivateDialogue();
            }

            //shoot
            if (Input.GetKeyDown(KeyCode.Mouse0) && Time.time > nextFire)
            {
                nextFire = Time.time + fireRate;
                StartCoroutine(ShotEffect());
                Vector3    rayOrigin = playerCamera.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 0));
                RaycastHit hit;

                /*if (Physics.Raycast(rayOrigin, playerCamera.transform.forward, out hit, gunRange))
                 * {
                 *  if (hit.rigidbody != null)
                 *  {
                 *      hit.rigidbody.AddForce(-hit.normal * hitForce);
                 *  }
                 * }*/
                if (Physics.SphereCast(rayOrigin, 0.5f, playerCamera.transform.forward, out hit, gunRange))
                {
                    if (hit.rigidbody != null)
                    {
                        hit.rigidbody.AddForce(-hit.normal * hitForce);
                    }
                }
            }
        }
        else
        {
            dialogueOn = true;
        }
    }