unity 方向光(Directional Light)角度转变实现白天到黑夜的变化

 把脚本挂载到Directional Light上

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Lesson12ess : MonoBehaviour
{
    public float roteSpeed;
    // Start is called before the first frame update
    

    // Update is called once per frame
    void Update()
    {
        this.transform.Rotate(Vector3.right * roteSpeed * Time.deltaTime);
    }
}

其他物体上的脚本实现此功能,需要声明一个Transform类型的变量,用来获取Directional Light的位置信息,在unity页面,将Directional Light拖到脚本组件对应的位置上即可,此外还要更改Update函数中的代码。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Lesson12ess : MonoBehaviour
{
    public Transform lightTransform;
    public float roteSpeed;
    // Start is called before the first frame update
    

    // Update is called once per frame
    void Update()
    {
        lightTransform.Rotate(Vector3.right * roteSpeed * Time.deltaTime);
    }
}

猜你喜欢

转载自blog.csdn.net/m0_73113333/article/details/142774735