Quantcast
Channel: Questions in topic: "invokerepeating"
Viewing all articles
Browse latest Browse all 220

Need Help with changing skyboxes

$
0
0
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.

Viewing all articles
Browse latest Browse all 220

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>