Untitled

 avatar
unknown
plain_text
6 months ago
1.2 kB
2
Indexable
using UnityEngine;

public class BlinkingLight : MonoBehaviour
{
    public Material emissiveMaterial;
    public color emissionColor = Color.red;
    public float blinkSpeed = 1.0f;
    public float minemission = 0.0f;
    public float maxemission = 5.0f;

    private float emissionValue;
    private bool isIncreasing = true;

    void update()
    {
        if (isIncreasing)
        {
            emissionValue += blinkSpeed * Time.deltaTime;
            if (emissionValue >= maxemission)
            {
                emissionValue = maxemission;
                isIncreasing = flase;
            }
        }
        else
        {
            emissionValue -= blinkSpeed * Time.deltaTime;
            if (emissionValue <= minemission)
            {
                emissionValue = minemission;
                isIncreasing = true;
            }
        }

        void OnValidate()
        {
            if(emissiveMaterial == null)
            {
                Renderer renderer = GetComponent<Renderer>();
                if (renderer != null)
                {
                    emissiveMaterial = renderer.material;
                }
            }
        }
    }
}
Editor is loading...
Leave a Comment