- Home /
change skybox via script help ?
Hey i'm trying to change the skybox material via javascript . i make this(down below) script and for some reason it's not working !! can anyone help me plz ! this is the script that i'v made ------------------------------------------------------------------------->
#pragma strict
var dayMaterial:Material;
var nightMaterial:Material;
var Timer : float = 20.0;
RenderSettings.skybox = dayMaterial;
function update()
{
Timer = Time.deltaTime;
if(Timer <=20.0)
{
RenderSettings.skybox = dayMaterial;
}
if(Timer <=10.0)
{
RenderSettings.skybox = nightMaterial;
}
}
Answer by MrSoad · Nov 13, 2014 at 06:06 PM
This will do roughly what you want, its is cut down version of your script and will change from your current skybox to the one selected in this script(in the inspector box for the material var) after 10 seconds. I have fixed all your errors and you should be able to build upon this for your specific needs. I've left the Timer var as public so you can see what is happening to it in the inspector window when running.
#pragma strict
public var mNight_Sky : Material;
public var Timer : float = 10f;
function Update() {
if (Timer > 0) {
Timer = Timer - Time.deltaTime;
}
if (Timer <= 0f) {
RenderSettings.skybox = mNight_Sky;
}
}
Answer by Zeko_Aliraqi2012 · Nov 14, 2014 at 10:36 AM
Wow it's really working thnx bro (MrSoad) ! if anyone want the new script for changing the sky box here it is ! Dose anyone know how to fade it like when it change not like booom it's changed > i want to fade it like bring down the skybox opacity with time !
#pragma strict
public var Night_Sky: Material;
public var Day_Sky: Material;
public var Timer : float = 20f;
function Update() {
if (Timer > 0) {
Timer = Timer - Time.deltaTime;
}
if (Timer <= 10f) {
RenderSettings.skybox = Day_Sky;
}
if (Timer <= 0f) {
RenderSettings.skybox = Night_Sky;
}
}
That is quite a lot harder, but if you don't $$anonymous$$d having a go at C# then take a look at this series of Video Tutorials that I found recommended on a post here when I was looking for the same thing :
http://www.youtube.com/watch?v=FTfv9JhkmIA
http://www.youtube.com/watch?v=Fmbi5uE7Bb4
These are vid's 3 and 4 which should show how to do this if I remember right(you are prob best starting form vid 1 though), think you also have to do some shader editing if I remember right.
Your answer
Follow this Question
Related Questions
change a material from multiple materials 1 Answer
how do you change a skybox material by name 1 Answer
Help Changing Materials On Button Click 0 Answers
Changing materials with array 0 Answers