您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
34 行
971 B
34 行
971 B
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class LightManager : MonoBehaviour
|
|
{
|
|
public GameObject directLight;
|
|
|
|
public static DateTime time;
|
|
|
|
private const float one_day_seconds = 86400f;
|
|
private const float offset = 0.0f;
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
time = DateTime.Now;
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
|
|
DateTime start_of_today = new DateTime(time.Year, time.Month, time.Day);
|
|
TimeSpan timeSpan = time - start_of_today;
|
|
float total_seconds = (float)timeSpan.TotalSeconds;
|
|
float x = (total_seconds - 21600) *180 / 43200 - offset;
|
|
if (x > 180) x = 180;
|
|
if (x < 0) x = 0;
|
|
directLight.transform.rotation = Quaternion.Euler(x,72,0);
|
|
if (x > 90) x = 180 - x;
|
|
directLight.GetComponent<Light>().intensity = x / 90;
|
|
}
|
|
}
|