/LightVariation.cs
Last active Aug 23, 2019
a simple script for varying the intensity of light with Unity 3D
| 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); | |
| } | |
| } |
This comment has been minimized.
This comment has been minimized.
|
Glad you liked it! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
mpcarolin commentedAug 22, 2019
Worked like a charm. Thanks!