This code is for a torch effect where I am reandomly changing the intensity and color of a light attached to it.
The problem is that when the colors change it is not a soft light but very intense.
Heres the code.
using UnityEngine;
using System.Collections;
public class LightFlicker : MonoBehaviour {
[Header("Hi!")]
public Light lt;
public float flickerRate;
public float timer;
public float intMin;
public float intMax;
public float intThreshold;
public float intStart;
public float intChange;
public float colorLerpTime;
public float colorChangeTime;
public int gMin;
public int gMax;
public Color newColor;
public Color oldColor;
// Use this for initialization
void Start () {
lt = GetComponent<Light>();
intStart = lt.intensity;
intMax = intStart + intThreshold;
intMin = intStart - intThreshold;
lt.color = Color.red;
oldColor = Color.yellow;
InvokeRepeating("ColorChange", 1, colorChangeTime * Time.deltaTime);
}
void ColorChange()
{
newColor = new Color (255,Random.Range(gMin,gMax),0,255);
lt.color = Color.Lerp(oldColor, newColor, colorLerpTime * Time.deltaTime);
oldColor = newColor;
}
// Update is called once per frame
void Update () {
timer -= Time.deltaTime;
if(timer < 0)
{
if( 0.5f < Random.value)
{
lt.intensity -= intChange;
}
if(0.5f > Random.value)
{
lt.intensity += intChange;
}
if(intMax < lt.intensity)
{
lt.intensity = intStart;
}
if(intMin > lt.intensity)
{
lt.intensity = intStart;
}
timer = flickerRate;
}
}
}
Here is a picture of the problem, notice how low the intensity is!
![alt text][1]
Its hard to see here but the RBGA here is:
R: 65025
G: 49456
B: 0
A: 255
Obviously the R and G are no good but not really sure why?