Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by laurienash · Feb 27, 2015 at 12:03 AM · animationskyboxloadleveldontdestroyonloadbasic

How to begin animated skybox at same point in sequence as when the scene ended?

Hello,

My game switches between three scenes. In the first scene I have an animated skybox, and on pressing space a new holding scene loads for a few seconds, after which a third scene loads. (and on pressing space again, the holding scene loads for a few seconds, and then switches to scene 1 again)

I would like the animated skybox to begin at the same point in the animation in the first and third scene.

I used Dontdestroyonload so the same first person controller is used in both the first and third scene, but I've just found that this doesn't work, as it will there will be an extra controller in the scene each time I switch, and also that I can't set the controller to inactive in the second holding scene, as I won't be able to carry it over to the third scene, as Dontdestroyonload doesn't work on inactive objects.

Does anyone know the best way of starting the animated skybox at the same point in the sequence as it was when the scene ended?

This is the script which animates the skybox:

 using UnityEngine;
 using System.Collections;
 public class t_change : MonoBehaviour {
 private Texture[] front;
 private Object[] fronto;
 
 private Texture[] up;
 private Object[] upo;
 
 private Texture[] left;
 private Object[] lefto;
 
 private Texture[] right;
 private Object[] righto;
 
 private Texture[] back;
 private Object[] backo;
 
 private Texture[] down;
 private Object[] downo;
 
 
 string cur_name;    
 private float sec=0;
 public float day = 48f; // Duration of the day in seconds
 float next_change;
     float prev_time=0;
 int current_hour=0;    
     float cur_time=0;
 int next_hour;
 float blend=0;    
     float moon_alpha;
     float light_var;
     void Start () {
     GameObject.Find("rot").transform.eulerAngles = new Vector3(-1f, transform.eulerAngles.y,transform.eulerAngles.z); ;
         this.fronto = Resources.LoadAll("dynamic_sky/front", typeof(Texture)); 
         this.front = new Texture[fronto.Length]; 
         this.righto = Resources.LoadAll("dynamic_sky/right", typeof(Texture)); 
         this.right = new Texture[fronto.Length]; 
         this.lefto = Resources.LoadAll("dynamic_sky/left", typeof(Texture)); 
         this.left = new Texture[fronto.Length]; 
         this.backo = Resources.LoadAll("dynamic_sky/back", typeof(Texture)); 
         this.back = new Texture[fronto.Length];
         this.upo = Resources.LoadAll("dynamic_sky/up", typeof(Texture)); 
         this.up = new Texture[fronto.Length]; 
         this.downo = Resources.LoadAll("dynamic_sky/down", typeof(Texture)); 
         this.down = new Texture[fronto.Length]; 
         //loading all the textures
         for (int i=0; i<=23; i++){
         this.front[i]=(Texture)this.fronto[i];  
             this.left[i]=(Texture)this.lefto[i];  
             this.right[i]=(Texture)this.righto[i];  
             this.up[i]=(Texture)this.upo[i];  
             
              this.back[i]=(Texture)this.backo[i];   
         }
         this.down[0]=(Texture)this.downo[0];   // - there is only one texture for down in this asset
             change_textures();
     }
     
     // Update is called once per frame
     void Update () {
         if (cur_time>10 && cur_time<22 && light_var<1){
         light_var+=Time.deltaTime*2f;
         } 
         if ((cur_time>22 || cur_time<10) && light_var>0){
             light_var-=Time.deltaTime*2f;
         }
         //
         if (cur_time>22 || cur_time<9 && moon_alpha<1){
         moon_alpha+=Time.deltaTime*2f;
         } 
         if ((cur_time>9&& cur_time<22) && moon_alpha>0){
             moon_alpha-=Time.deltaTime*2f;
         }
         GameObject.Find("rot").transform.Find("Sun").light.intensity=light_var;
         cur_time+=(Time.time-sec)*24f/day;
         GameObject.Find("rot").transform.eulerAngles = new Vector3(-cur_time*15f,transform.rotation.y,transform.rotation.z);
         
             GameObject.Find("rot").transform.Find("Moon").renderer.material.color = new Color(GameObject.Find("rot").transform.Find("Moon").renderer.material.color.r,GameObject.Find("rot").transform.Find("Moon").renderer.material.color.b,GameObject.Find("rot").transform.Find("Moon").renderer.material.color.g,moon_alpha);
          blend+=Time.time-sec;
     sec=Time.time;
         print ("time_"+ (cur_time-prev_time)+" "+cur_time+" "+current_hour);
         if (cur_time-prev_time>=1f) {
             prev_time++;
             change_textures();
             blend=0;
             
             if (cur_time >= 24f) {
                 cur_time=0;
                 prev_time=0;
             }
             current_hour=(int)Mathf.Floor(cur_time);
             }
         this.GetComponent<Skybox>().material.SetFloat("_Blend", (cur_time-prev_time));
         
     }
     
     void change_textures(){
         this.GetComponent<Skybox>().material.SetTexture("_FrontTex",front[current_hour]);
         
         this.GetComponent<Skybox>().material.SetTexture("_RightTex",right[current_hour]);
         
         this.GetComponent<Skybox>().material.SetTexture("_LeftTex",left[current_hour]);
         
         this.GetComponent<Skybox>().material.SetTexture("_BackTex",back[current_hour]);
         
         this.GetComponent<Skybox>().material.SetTexture("_UpTex",up[current_hour]);
         
         this.GetComponent<Skybox>().material.SetTexture("_DownTex",down[0]);
         change_2_textures();
     }
     
     void change_2_textures(){
         next_hour=current_hour+1;
         if (next_hour==24){
             next_hour=0;
         }
         this.GetComponent<Skybox>().material.SetTexture("_FrontTex2",front[next_hour]);
         
         this.GetComponent<Skybox>().material.SetTexture("_RightTex2",right[next_hour]);
         
         this.GetComponent<Skybox>().material.SetTexture("_LeftTex2",left[next_hour]);
         
         this.GetComponent<Skybox>().material.SetTexture("_BackTex2",back[next_hour]);
         
         this.GetComponent<Skybox>().material.SetTexture("_UpTex2",up[next_hour]);
         
         this.GetComponent<Skybox>().material.SetTexture("_DownTex2",down[0]);
         
     }
     
 
 }

Best, Laurien

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Mmmpies · Feb 27, 2015 at 04:05 PM 0
Share

That's a lot of code to read ;¬) so I'll try this as a comment first as it's just a good stab at what you want to do.

If you mean you've got a skybox that reacts to the time of day and your player is don't destroy on load just store the time that you leave one scene in a variable on the players main script and when the next (non-holding) scene loads grab that value for the start value of the skybox script.

Hope that makes sense.

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

go to other scene at the end of animation 2 Answers

What is the standard solution for preserving level data? 0 Answers

Can a 2D skybox be animated? 0 Answers

Delete duplicate gameobject on restart 1 Answer

InvokeRepeating on object with DontDestroyOnLoad 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges