I have this code that Change spot angle randomly between 'minAngle' and 'maxAngle' each 'interval' seconds:
public float interval = 0.7f;
public float minAngle = 2;
public float maxAngle = 10;
float timeLeft;
Light lt;
void Start()
{
lt = GetComponent<Light>();
lt.type = LightType.Spot;
timeLeft = interval;
}
void Update()
{
timeLeft -= Time.deltaTime;
if (timeLeft < 0.0)
{
timeLeft = interval;
lt.spotAngle = Random.Range(minAngle, maxAngle);
}
}
}
but i want the angle to change gradualy, for example if the angle is 2 and the new random number is 10, i want it to look like its growing gradualy. I supose i have to use a for? or some how take in consideration the previous value and lerp it?
previousAngle = currentAngle; timeLeft -= Time.deltaTime; – magdalena molinari Aug 25 '21 at 12:40
Mathf.Lerp
, which is the name of the lerp function acting on floats in Unity? (You should also tag your question Unity C# by the way) If you search for Unity answers you'll find examples of this that you can copy more directly. You've probably also found that code does not format nicely in comments, so edit your question when you want to add information to it. – DMGregory Aug 25 '21 at 12:48