- Home /
The question is answered, right answer was accepted
Lens Flare Scale Down On Distance???
Hi. How do I make a lens flare scale down on distance? I'm trying to make a car game and I have a flare as a turning light or headlight and when the camera is far away, the car and everything get scaled down, the flare remains the same, so the flare looks very big(the same size as the car and you cannot see anything else but the flare). Also, the game I'm working on is for Android so the flare resizing needs to be optimized. Any help is appreciated! I haven't tried to scale the flare from script based on the camera distance, since there are different cameras at different distance of the car and the flare has 20 elements(not 20 childs, 20 elements where the flare is imported).
Answer by GDGames0302 · Feb 13, 2021 at 01:28 PM
Hi. I found a post with the correct answer (Link: https://answers.unity.com/questions/18790/position-dependent-lens-flare-scale.html) :
using UnityEngine;
public class LensFlareFixedDistance : MonoBehaviour
{
private float Size;
public LensFlare Flare;
void Start()
{
if (Flare == null)
Flare = GetComponent<LensFlare>();
if (Flare == null)
{
Debug.LogWarning("No LensFlare on " + name + ", destroying.", this);
Destroy(this);
return;
}
Size = Flare.brightness;
}
void Update()
{
float ratio = Mathf.Sqrt(Vector3.Distance(transform.position, Camera.main.transform.position));
Flare.brightness = Size / ratio;
}
}
Follow this Question
Related Questions
Light Flares on Mobile 1 Answer
Disappearing flares 0 Answers
How do I create a "light pillar"? 1 Answer
URP Point light range doesn't increase light range? 2 Answers