x


Changing Skybox with toggle gui button

Hi,

How can I change the skybox material?

more ▼

asked Mar 18 '10 at 11:55 PM

maveryck21 gravatar image

maveryck21
254 35 36 49

This is a combination of two problems: How to make a GUI Toggle, and how to change the Skybox. If you can break your questions down into the composite elements and then post those as individual questions, there's a bigger chance that other people may also find the questions and answers useful (because they're more general).

Mar 19 '10 at 10:15 AM runevision ♦♦
(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first
var dayMaterial:Material;
var nightMaterial:Material;
private var ButtonText:String ="day";
RenderSettings.skybox = dayMaterial;

function OnGUI () {
    if (GUI.Button (Rect (10,10,150,50), ButtonText)) {
            if (RenderSettings.skybox == dayMaterial){
                ButtonText = "night";
                RenderSettings.skybox= nightMaterial;
            }else if(RenderSettings.skybox == nightMaterial){
                ButtonText = "day";
                RenderSettings.skybox= dayMaterial;
            }
    }
}
more ▼

answered Jul 26 '10 at 05:17 PM

alfrido gravatar image

alfrido
36 2

(comments are locked)
10|3000 characters needed characters left

The GUI.Toggle function returns the state of the toggle. true = on, false = off

toggleState = GUI.Toggle(toggleRect, toggleState, "toggle");
more ▼

answered Mar 19 '10 at 01:13 AM

Eric5h5 gravatar image

Eric5h5
103k 50 166 622

(comments are locked)
10|3000 characters needed characters left

I've found out the solution..here is the code I'm using

    toggleDayNightNew = GUI.Toggle (Rect(25, 20, 80, 30), toggleDayNight, "Day/Night");
    if(toggleDayNightNew != toggleDayNight)
    {
        if(toggleDayNightNew == true)
        {
            GameObject.Find("CrateCamera").GetComponent("toggleSky").applyDaySky();
        }
        else
        {
            GameObject.Find("CrateCamera").GetComponent("toggleSky").applyNightSky();
        }
        toggleDayNight = toggleDayNightNew;
    }
more ▼

answered Mar 19 '10 at 12:17 PM

maveryck21 gravatar image

maveryck21
254 35 36 49

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x234
x219

asked: Mar 18 '10 at 11:55 PM

Seen: 5563 times

Last Updated: Jul 25 '12 at 10:29 PM