- Home /
Toggling between skyboxes/lighting with a button
So I'm working in Unity to create interactive versions of architectural models (like, you can walk around a model of a building and interact with it to preview how it'll look when its built), and I want to create a key so I can toggle whether you're seeing the building at night or during the day. I don't even know where to begin.
I've imported a set of skyboxes, do I create a script for this to attach to the camera? do I put it in with my player controller? do I make it a game object? If someone could even point me in a direction to work, I would really appreciate it. I'm new to coding and to Unity, but it seems like this should be something I can do. I'm using C#.
Answer by mikelortega · May 27, 2015 at 10:42 PM
You can try adding a script like this to any GameObject. It is just an easy example.
This script changes the skybox when you press the keyboard keys 1, 2, 3 and 4. In the editor you have to define Skybox 1, 2, 3 and 4 materials.
 using UnityEngine;
 
 public class ChangeSkybox : MonoBehaviour
 {
     public Material m_Skybox1;
     public Material m_Skybox2;
     public Material m_Skybox3;
     public Material m_Skybox4;
     
     void Update()
     {
         if (Input.GetKeyDown(KeyCode.Alpha1))
             RenderSettings.skybox = m_Skybox1;
 
         if (Input.GetKeyDown(KeyCode.Alpha2))
             RenderSettings.skybox = m_Skybox2;
 
         if (Input.GetKeyDown(KeyCode.Alpha3))
             RenderSettings.skybox = m_Skybox3;
 
         if (Input.GetKeyDown(KeyCode.Alpha4))
             RenderSettings.skybox = m_Skybox4;
     }
 }
Your answer
 
 
             Follow this Question
Related Questions
Can you find a dominant light direction from the spherical harmonics of a skybox? 0 Answers
Toggling camera with one key,Toggle Camera with one key? 1 Answer
Lighting differencies between desktop and android. 1 Answer
new project aren't set up right 1 Answer
Toggle between scripts with a script? 2 Answers
