Search Unity

Toggle Sky with GUI

Discussion in 'Scripting' started by 3DJayC, Jul 29, 2014.

  1. 3DJayC

    3DJayC

    Joined:
    Jul 29, 2014
    Posts:
    33
    Hello,

    I'm a 3D artist and I'm new to Unity,
    I discovered a lot of very cool fonction using Unity, it's very cool!

    I'm learning script and I have some problems in scripting some fonction.

    I'd like to learn how assign to switch component of an object by clicking custom GUITexture?
    In fact, I made two HUD buttons and I'd like to make them assign an object to a public value to antother.

    May be I'm not clear about what I'm searching for...

    May be someone has some cool tuts to share?

    Many thanks!

    (sorry for my poor english)

    ++
     
  2. smitchell

    smitchell

    Joined:
    Mar 12, 2012
    Posts:
    702
    I'm not sure if this is what you meant but did you want to toggle a skybox? if you did then you could do something like this:

    (c Sharp)

    Code (CSharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class Skybox_Toggle : MonoBehaviour {
    6.  
    7.     public Skybox skybox1;
    8.     public Skybox skybox2;
    9.  
    10.     void OnGUI () {
    11.         if(GUI.Button(new Rect(0, 0, 300, 140), "Toggle Skybox")) {
    12.             if(RenderSettings.skybox == skybox1) {
    13.                 RenderSettings.skybox = skybox2.material;
    14.             } else {
    15.                 RenderSettings.skybox = skybox1.material;
    16.             }
    17.         }
    18.     }
    19. }
    20.  
     
    FuzzyBalls likes this.
  3. smitchell

    smitchell

    Joined:
    Mar 12, 2012
    Posts:
    702
    (JS)

    Code (CSharp):
    1.  
    2. #pragma strict
    3.  
    4. var skybox1 : Skybox;
    5. var skybox2 : Skybox;
    6.  
    7. function OnGUI () {
    8.     if(GUI.Button(Rect(0, 0, 150, 40), "Toggle Skybox")) {
    9.         if(RenderSettings.skybox == skybox1) {
    10.             RenderSettings.skybox = skybox2.material;
    11.         } else {
    12.             RenderSettings.skybox = skybox1.material;
    13.         }
    14.     }
    15. }
     
    FuzzyBalls likes this.