在Unity场景中控制日夜的轮转

一、介绍

目的:通过在Unity场景中添加C#脚本完成日夜轮转的效果。

软件环境:Unity 2017.3.0f3,VS2013

二、操作过程

通过拖拽场景中的Directional Light我们知道,只要控制好平行光的旋转就可以模拟出轮转的更替,所以我们要在Directional Light中添加相应的脚本文件。

(如何添加脚本文件,可参考 Unity入门教程(上)

C#代码如下:

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

public class DayNightControl : MonoBehaviour {

    public float rotateSpeed = 10;  //设置平行光旋转的速度

    // Use this for initialization
    void Start () {
        
    }
    
    // Update is called once per frame
    void Update () {
        transform.Rotate(Vector3.up * rotateSpeed * Time.deltaTime, Space.Self); //绕自身旋转
    }
}

参考资料链接: transform.Rotate

原文地址:https://www.cnblogs.com/OctoptusLian/p/8819551.html