- Home /
Need Help with changing skyboxes
I am trying to make an endless runner and I have made 20 Skyboxes. I want them to change every few minutes but for testing's sake, I'm keeping it 5 seconds. I want skyboxes to change in a random manner. Here is the script but there seems to be some errors (I'm only including the important things in the code)
 using UnityEngine;
 using UnityEngine.SceneManagement;
  
  public class GameManager : MonoBehaviour
  {
      public float skyChangeStart = 5f;
      public float skyChangeTime = 5f;
      public Material[] randMat = new Material[20];
      public float time;
  
      public void SkyChange()
      {
          RenderSettings.skybox = randMat[Random.Range(0, randMat.Length)];
      }
      public void Update()
      {
          InvokeRepeating("SkyChange", skyChangeStart, skyChangeTime);
      }
  }
and I have referenced all the materials in randMat in unity. I don't know what went wrong but after 5 seconds, I can see the skyboxes changing like every millisecond like crazy fast! I want it to change every 5 seconds. And one more thing is that the change is only seen in Scene view, not in Game View. I even replaced the InvokeRepeating with this code
 time += Time.deltaTime;
  
          if (time == skyChangeTime)
          {
              SkyChange();
              time = 0;
  
          }
but that's giving the same thing. The same rapid skybox changing. I don't know what to do please help.
Don't use invoke repeating in update use it in
 Start(){    }
Your answer
 
 
             Follow this Question
Related Questions
Creating Material from String (Unity 5.6) 1 Answer
How do I get rid of the black line in Unity Sky 1 Answer
How to change the reflection according to skybox-material? 2 Answers
Skybox is reflecting from game object in some devices? 0 Answers
Can't apply Skybox material to Skybox type variable 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
               
 
			 
                