Last active
January 27, 2022 19:49
-
-
Save demonixis/6475766 to your computer and use it in GitHub Desktop.
a simple script for varying the intensity of light with Unity 3D
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class BlinkLight : MonoBehaviour | |
{ | |
Light light; | |
public float minIntensity = 0.0f; | |
public float maxIntensity = 1.5f; | |
public float frequency = 0.01f; | |
public float phase = 0.0f; | |
public AudioClip maxSound = null; | |
void Start () | |
{ | |
light = GetComponent<Light>(); | |
} | |
void Update () | |
{ | |
float x = (Time.time + phase) * frequency; | |
x = x - Mathf.Floor(x); // normalized value to 0..1 | |
light.intensity = maxIntensity * Mathf.Sin(2 * Mathf.PI * x) + minIntensity; | |
if (light.intensity >= (maxIntensity - 1) && maxSound != null) | |
audio.PlayOneShot(maxSound); | |
} | |
} |
Glad you liked it!
signed up specially to thank you for this excellent script
Thanks!
thank you
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Worked like a charm. Thanks!