Hello Friends,
As I’m following the beginner C# scripting tutorials, I’ve run into the following issues:
- The code being taught for light intensity (light.intensity) is obsolete at this point and my attempt at remedying the issue, based on the Unity Scripting API documentation, has led to an error that I’m still trying to figure out:
Here’s the .cs file that’s attached to a Point Light with the Point Light object set as lt (see screenshot below).
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/* Lerp - Linear Interpolation
* Allows for a smooth transition between values
* Lerp below will lerp 3 properties of the light: position, color, intensity.
* */
public class LerpLight : MonoBehaviour {
public float smooth = 2;
public Light lt;
private float newIntensity;
void Awake(){
// Get light component
lt = GetComponent<Light>();
// Sets current intensity of the object to newIntensity
newIntensity = lt.intensity;
}
// Update is called once per frame
void Update () {
IntensityChanging ();
}
void IntensityChanging(){
float intensityA = 0.5f;
float intensityB = 5f;
if (Input.GetKeyDown (KeyCode.A))
newIntensity = intensityA;
if (Input.GetKeyDown (KeyCode.D))
newIntensity = intensityB;
// Mathf.Lerp(From intensity, To intensity, Distance between From and To * Time it takes to get there)
lt.intensity = Mathf.Lerp (lt.intensity, newIntensity, Time.deltaTime * smooth);
}
}
-
The Linear Interpolation video lesson, in general, has some negative reviews saying it’s incorrectly using the Lerp code. I certainly don’t know any better so had I not run into the first issue, I wouldn’t have noticed the comments further explaining the discrepancies. It looks like Time.deltaTime doesn’t really ‘belong’ in the third Lerp property which is reflected in the partially updated written lesson.
-
Is using Time.delta.Time within Lerp inefficient and/or bad practice? It seems like the destination is never reached and it’s left constantly updating.
Any insight is appreciated!
Thanks,
Zach