Пример #1
0
    void Update()
    {
        saved = PlayerPrefs.GetInt("saveGame");

        //lose health in extreme temperatures
        if (playerTemperature <= 0)
        {
            playerInventoryScript.GetComponent <PlayerScript> ().health -= -playerTemperature * Time.deltaTime * 0.2f;
        }
        if (playerTemperature > 35)
        {
            playerInventoryScript.GetComponent <PlayerScript> ().health -= (playerTemperature - 35) * Time.deltaTime * 0.2f;
        }

        targetTemp = 20;

        //calculate temperature repeatedly
        if (currentSeason == 0)
        {
            //autumn
            targetTemp -= (float)currentDayInSeason;
        }
        else if (currentSeason == 1)
        {
            //winter
            if (currentDay < 6)
            {
                targetTemp -= (float)currentDayInSeason + 12;
            }
            else
            {
                targetTemp -= -(float)currentDayInSeason + 17;
            }
        }
        else if (currentSeason == 2)
        {
            //spring
            targetTemp += (float)currentDayInSeason - 12;
        }
        else
        {
            //summer
            if (currentDay < 6)
            {
                targetTemp += (float)currentDayInSeason + 2;
            }
            else
            {
                targetTemp += -(float)currentDayInSeason + 7;
            }
        }
        if (time < nightBeginTime && time > duskBeginTime || time > dawnBeginTime)
        {
            targetTemp -= 6;
        }
        else if (time > nightBeginTime)
        {
            targetTemp -= 12;
        }
        //slowly change ambient to target
        if (ambientTemperature < targetTemp)
        {
            ambientTemperature += Time.deltaTime / 6;
        }
        else if (ambientTemperature > targetTemp)
        {
            ambientTemperature -= Time.deltaTime / 6;
        }
        if (Mathf.Abs(ambientTemperature - targetTemp) < 0.5f)
        {
            ambientTemperature = targetTemp;
        }

        //clothing, fires, and character type will affect player warmth
        targetPlayerTemp = ambientTemperature + 3;
        if (playerInventoryScript.findClosestFireToPlayer(4) != null)
        {
            targetPlayerTemp += (4 - Vector3.Distance(playerInventoryScript.findClosestFireToPlayer(4).transform.position, playerInventoryScript.gameObject.transform.position)) * 6f;
        }

        //slowly change playerTemp to target
        if (playerTemperature < targetPlayerTemp)
        {
            playerTemperature += Time.deltaTime / 6;
        }
        else if (playerTemperature > targetPlayerTemp)
        {
            playerTemperature -= Time.deltaTime / 6;
        }
        if (Mathf.Abs(playerTemperature - targetPlayerTemp) < 0.5f)
        {
            playerTemperature = targetPlayerTemp;
        }

        ambientTemperatureDisplay.text = ((int)ambientTemperature).ToString() + " ºc";
        playerTemperatureDisplay.text  = ((int)playerTemperature).ToString() + " ºc";

        Light sunlight = GameObject.Find("Directional Light").GetComponent <Light>();

        if (time < duskBeginTime)
        {
            targetSunColor = new Color(1, 1, 0.9f);
        }
        else if (time < nightBeginTime)
        {
            targetSunColor = new Color(1, 0.42f, 0.42f);
        }
        else if (time < dawnBeginTime)
        {
            targetSunColor = new Color(0, 0, 0);
        }
        else
        {
            targetSunColor = new Color(1, 0.6f, 0.6f);
        }
        if (Mathf.Abs(targetSunColor.r - sunlight.color.r) > 0.06f)
        {
            if (sunlight.color.r < targetSunColor.r)
            {
                sunlight.color = new Color(sunlight.color.r + Time.deltaTime * 0.16f, sunlight.color.g, sunlight.color.b);
            }
            else
            {
                sunlight.color = new Color(sunlight.color.r - Time.deltaTime * 0.16f, sunlight.color.g, sunlight.color.b);
            }
        }
        if (Mathf.Abs(targetSunColor.g - sunlight.color.g) > 0.06f)
        {
            if (sunlight.color.g < targetSunColor.g)
            {
                sunlight.color = new Color(sunlight.color.r, sunlight.color.g + Time.deltaTime * 0.16f, sunlight.color.b);
            }
            else
            {
                sunlight.color = new Color(sunlight.color.r, sunlight.color.g - Time.deltaTime * 0.16f, sunlight.color.b);
            }
        }
        if (Mathf.Abs(targetSunColor.b - sunlight.color.b) > 0.06f)
        {
            if (sunlight.color.b < targetSunColor.b)
            {
                sunlight.color = new Color(sunlight.color.r, sunlight.color.g, sunlight.color.b + Time.deltaTime * 0.16f);
            }
            else
            {
                sunlight.color = new Color(sunlight.color.r, sunlight.color.g, sunlight.color.b - Time.deltaTime * 0.16f);
            }
        }
        //change dayCount display
        displayClock.transform.GetChild(17).GetComponent <Text> ().text = "Day " + currentDay.ToString();
        time += Time.deltaTime / 30;
        if (time >= 16)
        {
            newDay();
        }
        displayClock.transform.GetChild(16).eulerAngles = new Vector3(0, 0, -time * 22.5f + 90);
        touchContainsUI = false;
        foreach (Rect rect in onScreenUI)
        {
            if (rect.Contains(Input.mousePosition))
            {
                touchContainsUI = true;
                break;
            }
        }
    }