HI,
I have a 2D game and I want to have a day/night cycle. I have it working but performance is slow. I have this script attached to ALL my sprites, so that they get brighter and darker based on the suns position and i would like to add a cloud cover adjustment as well. right now there are about 30 sprites in the scene.
Is there a way I can constantly update the brightness on everything without slowing things down?
Thanks!!
public class Shadow: MonoBehaviour {
public float sunPosition; // starting position is 5.6
GameObject oSun;
float RGB;
public float minLight = 0.05f;
public float startLight = 5.9f;
void Update () {
oSun = GameObject.Find ("sun");
SpriteRenderer renderer = GetComponent<SpriteRenderer> ();
sunPosition = oSun.transform.position.y;
RGB = (sunPosition - startLight);
if (RGB < minLight)
renderer.color = new Color (minLight, minLight, minLight, 1f);
if (RGB > minLight && RGB <= 1.0f)
renderer.color = new Color (RGB, RGB, RGB, 1f);
}
}