Quantcast
Channel: Questions in topic: "invokerepeating"
Viewing all articles
Browse latest Browse all 220

Decreasing a value over time, called by InvokeRepeating

$
0
0
I'm attempting to create an effect in my game in which two discreet spot lights lower and raise their intensity every so often to give the impression that the player is actually travelling through space. The method I'm using does work to an extent; void Start () { InvokeRepeating("LightChange", 5, 30); } void LightChange() { if (Random.value >= 0.5f) { dirLight1.intensity -= (Mathf.Clamp(0.05f * Time.deltaTime, 0.00f, 0.5f)); dirLight2.intensity += (Mathf.Clamp(0.05f * Time.deltaTime, 0.00f, 0.5f)); } else { dirLight1.intensity += (Mathf.Clamp(0.05f * Time.deltaTime, 0.00f, 0.5f)); dirLight2.intensity -= (Mathf.Clamp(0.05f * Time.deltaTime, 0.00f, 0.5f)); } } It works in that the function is called and the value for the light intensity does indeed change, although it only changes for a moment (from .5 to .45) whereas the intended effect is that the values would decrease/increase to their minimum/maximum respectively.

Viewing all articles
Browse latest Browse all 220

Latest Images

Trending Articles



Latest Images