Пример #1
0
    void Update()
    {
        if (vitalClass.getSoberness() != 100.0f)
        {
            var md = new Vector2(-Input.GetAxis("Mouse X"), -Input.GetAxis("Mouse Y"));

            md = Vector2.Scale(md, new Vector2(sensitivity * 2 * smoothing, sensitivity * 2 * smoothing));
            //lerp the x and y pos of the mouse as the player moves the mouse
            smoothV.x = Mathf.Lerp(smoothV.x, md.x, Time.deltaTime * smoothing);
            smoothV.y = Mathf.Lerp(smoothV.y, md.y, Time.deltaTime * smoothing);

            mouseLook += smoothV;
        }
        else
        {
            var md = new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"));

            md         = Vector2.Scale(md, new Vector2(sensitivity * smoothing, sensitivity * smoothing));
            smoothV.x  = Mathf.Lerp(smoothV.x, md.x, 1f / smoothing);
            smoothV.y  = Mathf.Lerp(smoothV.y, md.y, 1f / smoothing);
            mouseLook += smoothV;
        }


        mouseLook.y = Mathf.Clamp(mouseLook.y, -90f, 90f);
    }
Пример #2
0
    private void Update()
    {
        //increases and lowers the fov over time
        if (fovIncrease)
        {
            FPPCamera.fieldOfView += fovModifier * Time.deltaTime;

            if (FPPCamera.fieldOfView >= 140.0f)
            {
                fovIncrease = false;
            }
        }
        else
        {
            FPPCamera.fieldOfView -= fovModifier * Time.deltaTime;

            if (FPPCamera.fieldOfView <= 120.0f)
            {
                fovIncrease = true;
            }
        }

        //each frame, increase the soberness of the player
        vitals.setSoberness((100.0f / reduceDrunkSpeed) * Time.deltaTime);

        //slowly change the smooth value for the camera lerp each frame
        //smooth = vitals.getSoberness() / 10.0f;

        //slowly lower the fov modifer each frame
        fovModifier -= ((10.0f / reduceDrunkSpeed) * Time.deltaTime);

        //update the alpha of the drunk overlay image
        float drunkOverlayAlpha = (0.1f / 100.0f) * (100.0f - vitals.getSoberness());

        drunkOverlay.color = new Color(drunkOverlay.color.r, drunkOverlay.color.g, drunkOverlay.color.b, drunkOverlayAlpha);
        //print("drunkOverlayAlpha = " + drunkOverlay.color.a);

        //update the alpha of the drunk fade image
        float drunkFadeAlpha = (1.0f / 100.0f) * (100.0f - vitals.getSoberness());

        drunkFade.color = new Color(drunkFade.color.r, drunkFade.color.g, drunkFade.color.b, drunkFadeAlpha);
        //print("drunkFadeAlpha = " + drunkFade.color.a);

        //if the player is now sober again
        if (vitals.getSoberness() >= 100.0f)
        {
            drunkEnding = true;

            //ensures the sober value is exactly 100.0f | 100%
            vitals.setSoberness(100.0f, true);

            //reset the player fov over time
            FPPCamera.fieldOfView = Mathf.Lerp(FPPCamera.fieldOfView, initialFOV, resetFOVTimer);
            resetFOVTimer        += (1.0f / 100.0f) * Time.deltaTime;
        }

        //only destroy the script one the fov has finished resetting
        if (FPPCamera.fieldOfView - Mathf.Abs(initialFOV) < 1.0f && drunkEnding)
        {
            destroyScript();
        }
    }