i am struggling to lerp the skybox atmosphere and cant seem to get it right, can anyone get this code to work please
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ACCESSSKYBOX2 : MonoBehaviour {
public float duration;
private float t = 0;
void Start()
{
}
void Update (){
RenderSettings.skybox("_AtmosphereThickness") = Mathf.Lerp(0, 1,t);
while (t < 1){
t += Time.deltaTime/duration;
}
}
}
Presumably you’re trying to change the value of this setting over a period of time. That means making the change over the course of several frames.
If you do things like you have now with the while loop, “t” will move from 0 to 1 in a single frame. Then, when the next frame comes, and Update runs again, t will be 1. That’s not what you want!
Remember, Update runs once per frame. So we don’t need a while loop at all. You can fix this simply by pulling your t += Time.deltaTime/duration; out of the while loop. Delete the loop, it’s not needed at all.
Without the loop, t will increment by a little bit each frame! Because Update() runs once per frame. Make sense?
getting a red error for some reason, i am sure that it copiled without error yesterday before i posted the code, error: The member `UnityEngine.RenderSettings.skybox’ cannot be used as method or delegate
i have many lerp’s running fine in other scripts but trying to lerp the atmosphere on the skybox is beating me for some reason? help
The skybox property is just a Material. Assign your Material to it, don’t call it like a function.
Also, as Praetor noted, your while loop instantaneously executes all at once, until you set Time.timeScale to zero at which point you lock up Unity solid and have to restart. DO NOT LOOP endlessly in Unity functions. Unity locks up whenever it calls you and does nothing until you return. Always.