一、介绍

目的:通过在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

 

相关文章:

  • 2022-12-23
  • 2021-07-29
  • 2021-09-06
  • 2021-12-28
  • 2021-09-30
  • 2021-06-18
  • 2021-07-26
  • 2021-06-02
猜你喜欢
  • 2022-12-23
  • 2021-04-17
  • 2021-10-16
  • 2021-12-10
  • 2021-12-20
  • 2021-11-22
  • 2021-08-09
相关资源
相似解决方案