- Home /
How can I reset the exposing face of a rotating skybox at the beginning of a new scene?,
Hi
I have a game with several levels. I used the code below to make the skybox rotate constantly.
RenderSettings.skybox.SetFloat ("_Rotation", Time.time * 0.2f);
Now I'd like to reset the rotation of my skyboxes at the beginning of each level and make it start rotating again from point zero (not continuing the rotation point of the previous level). I cannot access the component "Rotation" on the inspector for my skybox via something like "GetComponent<>" or such things.
Could someone please help me how I can set the component "Rotation" of my skyboxes to zero on my inspector at the start of each level?
Thank you in advance.
Depending on how you load the new scene, I guess the best way would be to set the _Rotation
varying to 0 just before calling Scene$$anonymous$$anager.Load()
.
Duh, sorry, I misread the question, forgive it, @Hellium gave you the correct answer.
Answer by Hellium · Sep 25, 2019 at 07:39 PM
private float sceneStartTime;
private void Start()
{
sceneStartTime = Time.time;
}
private void Update()
{
RenderSettings.skybox.SetFloat ("_Rotation", (Time.time - sceneStartTime) * 0.2f);
}
Or more simply (thanks to Mouton suggestion in the comments)
private void Update()
{
RenderSettings.skybox.SetFloat ("_Rotation", Time.timeSinceLevelLoad * 0.2f);
}
It can be improved with https://docs.unity3d.com/ScriptReference/Time-timeSinceLevelLoad.html
:
RenderSettings.skybox.SetFloat ("_Rotation", Time.timeSinceLevelLoad * 0.2f);
@$$anonymous$$outon, @Hellium Thank you both for the great help.
Your answer
Follow this Question
Related Questions
rotate skybox 0 Answers
Need help with 24 Hour timing script. 1 Answer
How to rotate a skybox in relation to the camera 0 Answers
new project aren't set up right 1 Answer