- Home /
Lerp RenderSettings skybox
I want to switch my skybox from a day material to a night material for this I use :
Material night;
int skyboxflag = 0;
int flag = 0;
float t;
public float smooth = 1;
void Start () {
night = Resources.LoadAll("Night_mat",typeof(Material))[0] as Material;
}
void Update () {
if (skyboxflag == 1) {
if(flag == 0){
t = Time.time;
flag = 1;
}
RenderSettings.skybox.Lerp(RenderSettings.skybox, night,(Time.time - t)/smooth);
if(Time.time - t > smooth){
skyboxflag = 0;
}
}
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.name == "Avatar") {
skyboxflag = 1;
}
}
but nothing happens I keep having the day skybox.
what is the correct way to change the skybox smoothly from a material to another
Thank you
Answer by chaozz · Mar 06, 2015 at 12:35 PM
I have the same problem in Unity 5. I was using http://wiki.unity3d.com/index.php?title=SkyboxBlended in Unity 4, but that shader no longer works in Unity 5. Does anyone have an idea how to do skybox blending in Unity 5?
EDIT: Found a fix!
This Skybox Blending shader works in Unity 5. http://answers.unity3d.com/questions/371078/having-a-changing-skybox-depending-on-location-of.html
Answer by pronobroy · Jun 15, 2016 at 06:19 AM
using UnityEngine; using System.Collections;
public class dayknight : MonoBehaviour {
public Material mat;
public Material day;
public Material skyBox;
float t = 0.02f;
float a;
// Use this for initialization
void Start ()
{
RenderSettings.skybox.Lerp(skyBox, mat, 0.5f); //Here assaying mat matiral as default .
}
// Update is called once per frame
void Update ()
{
a = (Time.time *4) % 360;
transform.eulerAngles = new Vector3(transform.rotation.x + a , transform.rotation.y, transform.rotation.z);
if(a > 25 && a < 150 )
{
//Changing default to day matiral skybox.
RenderSettings.skybox.Lerp(skyBox,day,0.5f * Time.deltaTime);
}
else if (a > 150 && a < 185)
{
//Changing day matiral to mat matiral
RenderSettings.skybox.Lerp(skyBox,mat,0.5f*Time.deltaTime);
}
}
}
Hope that it will help you!!!!!!
@pronobroy Hi! I encounter a problem when using RenderSettings.skybox.Lerp. The link below shows the same problem with $$anonymous$$e. It seems to work only once. http://forum.unity3d.com/threads/rendersettings-skybox-lerp-not-cooperating.287566/ So now I am using Color.Lerp and then set the color to my skybox.
Answer by jampakdd · Feb 09, 2020 at 01:16 AM
@Tarikm I just made a video about this because a lot of people are saying it's not possible to do in script but it definitely is!
https://www.youtube.com/watch?v=d-cq9ufhkIg&feature=youtu.be
I hope this video is helpful to people!
Your answer
Follow this Question
Related Questions
renderer.material.lerp() doesn't work in unity 1 Answer
Skybox always black on MacOS 0 Answers
How to rotate a skybox in relation to the camera 0 Answers
Use Skybox material on Cube 0 Answers