상세 컨텐츠

본문 제목

라이트(Light)

유니티/기능

by MJ_119 2024. 6. 26. 00:42

본문

 

 

 

 - 전구처럼 깜빡깜빡하는 효과

using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;

public class Test : MonoBehaviour
{
    Light theLight;

    private float targetIntensity;
    private float currentIntensity;

    private void Start()
    {
        theLight = GetComponent<Light>();
        currentIntensity = theLight.intensity;
        targetIntensity = Random.Range(0.1f, 10f);
    }

    void Update()
    {
        if (Mathf.Abs(targetIntensity - currentIntensity) >= 0.01)
        {
            if (targetIntensity - currentIntensity >= 0)
                currentIntensity += Time.deltaTime * 3f;
            else
                currentIntensity -= Time.deltaTime * 3f;

            theLight.intensity = currentIntensity;
            theLight.range = 10 + currentIntensity;

        }
        else
        {
            targetIntensity = Random.Range(0.1f, 10f);
        }
    }
}

관련글 더보기