unity 燈光,手電筒等 light

在物件中再設定一個Light Component() 就可以有燈光。
range = 控制範圍
color = Color(lightColorR,lightColorG,lightColorB);


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

public class LightControll : MonoBehaviour
{
    public float duration = 1;
    public Light lt;
    // Start is called before the first frame update
    void Start()
    {
        lt = GetComponent<Light>();
    }

    // Update is called once per frame
    void Update()
    {
        float phi = Time.time / duration * 2 * Mathf.PI; //時間無限增加
        float amplitude = Mathf.Cos(phi) * 0.5f; //用三角函數讓她一下正一下負 1 0 -1 0 , *0.5 是讓他燈光變暗(亮度減少)
        lt.intensity = amplitude;

        print(Mathf.Cos(phi));

        //lt.intensity = 0.5f;
    }
}

留言

這個網誌中的熱門文章

無法載入檔案或組件 'System.IO.Compression' 或其相依性的其中之一。

MongoDB 入門

javascript 更改屬性及創建標籤