- Home /
Change skybox at runtime?
For this time, I will use OnTriggerEnter
I wanted to make players when enter trigger, it will change the skybox. Is it possible?
Answer by vexe · Oct 09, 2013 at 09:15 AM
var otherSkybox : Material; // assign via inspector
function OnTriggerEnter(other : Collider)
{
RenderSettings.skybox = otherSkybox;
}
I'm not really sure you'd want that logic though, this way ANYTHING that enters the trigger, will change the skybox. You might to do that only for a certain object, like your player for example:
function OnTriggerEnter(other : Collider)
{
if (other.tag == "Player")
RenderSettings.skybox = otherSkybox;
}
But again, not happy about it, what if your player enters the trigger again? You don't have to change the skybox
again cause you already did, so add another check:
function OnTriggerEnter(other : Collider)
{
if (other.tag == "Player" && RenderSettings.skybox != otherSkybox)
RenderSettings.skybox = otherSkybox;
}
Answer by maaz0011 · Feb 17, 2017 at 09:14 AM
this code you can use for adding multiple materials for skybox, and the better way to create your own skybox is download 360 image which must be in bigger in width and also in height after that you can change their Texture Type from texture into Cubemap and same with their mapping into Latitude-Longitude Layout(cylindrical) and then click on Apply to make these changes after doing these steps you are going to create to a material and change their shader type into Skybox/Cubemap and add that image that you recently change their setting , and then use these in array. i hope it will helpful for you .
using UnityEngine; using System.Collections; using UnityEngine.Rendering;
public class skybox : MonoBehaviour {
public Material[] secondSkybox;
public static int i = 0;
public void skyboxOn()
{
if (i == 0) {
RenderSettings.skybox = secondSkybox[0];
i++;
}
else if(i==1)
{
RenderSettings.skybox = secondSkybox[1];
i++;
}else if(i==2)
{
RenderSettings.skybox = secondSkybox[2];
i=0;
}
}
}
this code you can use for adding multiple materials for skybox, and the better way to create your own skybox is download 360 image which must be in bigger in width and also in height after that you can change their Texture Type from texture into Cubemap and same with their mapping into Latitude-Longitude Layout(cylindrical) and then click on Apply to make these changes after doing these steps you are going to create to a material and change their shader type into Skybox/Cubemap and add that image that you recently change their setting , and then use these in array. i hope it will helpful for you .