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 serafin_alvarez · May 09, 2015 at 07:22 AM · animationloadingguitexture

Animated GUI.DrawTexture while game is loading

Hi,

I want my game to display a screen with a simple animation while it loads. It's a full screen animation made with 4 frames, in loop. I want this animation to show for at least 30 seconds even if the following scene loads faster than that (the animation contains some text to be read). It has to be full screen in whichever screen resolution, with a fixed aspect ratio, without being cropped.

I did it with a single image, but being 30 seconds with no movement or change it seems that the game crashed or something, so now I want to add other 3 images so every 0.5 seconds a different one is shown in a sequence (all of them are the same image with the addition of a small drawing that mutates a bit on each frame). Here's the code that I'm using (C#), but my coding skills are very limited and have no idea how to implement the solutions that I've found online. Any help would be appreciated. Thanks.

 using UnityEngine;
 using System.Collections;
 
 public class creditos : MonoBehaviour {
     
     private float ContadorSaltar;
     private float TiempoEstancia = 30.0f;
     public GUIStyle estiloNegro;
 
     public Texture2D[] fondos;
 
     // Update is called once per frame
     void Update () {
         ContadorSaltar += 1 * Time.deltaTime;
         if ( ContadorSaltar >= TiempoEstancia ){
             Application.LoadLevel("Scene1");
         }
     }
 
     // Update is called once per frame
     void OnGUI () {
         float anchura = Screen.width / 1.8f;
         GUI.Button(new Rect(0,0,Screen.width, Screen.height),"",estiloNegro);
         GUI.DrawTexture(new Rect(0,Screen.height / 2.0f - anchura / 2.0f,Screen.width,anchura),fondos[0]);
     }
 }
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 serafin_alvarez · May 11, 2015 at 08:19 AM 0
Share

After some more research, I think that one approach in pseudocode would be something like:

  • Display a scene that contains the animation, start a counter in seconds, switch frames every 0.5 seconds

  • Load the following scene asynchronously and wait. $$anonymous$$eanwhile, continue to display the animation until the counter reaches 30 seconds

  • Then, jump to the following scene

Would anyone help me to translate this to actual code to achieve that please? Thanks.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by phxvyper · May 11, 2015 at 03:40 AM

You can use a coroutine with this function:

http://docs.unity3d.com/ScriptReference/Application.LoadLevelAsync.html

Essentially, just pause your current scene and begin the 30-second loading sceen, or load your loading screen scene. Then begin the coroutine with that LoadLevelAsync function, and check to see if the AsyncOperation.isDone property that is returned returns true. If it is true then wait until the 30 second mark has passed. If the 30 second mark has already passed, then wait until isDone is true... or use Load() function on that scene since it's probably already mostly loaded.

Comment
Add comment · Show 1 · Share
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 serafin_alvarez · May 11, 2015 at 08:16 AM 0
Share

Hi @phxvyper , thanks for your help.

I'm trying to do that, but cannot get it to work.

Ins$$anonymous$$d of an animation I'm using a fake progress bar now. But it doesn't display the bar, and it doesn't load the scene either.

 using UnityEngine;
 using System.Collections;
 
 public class creditos2 : $$anonymous$$onoBehaviour {
     
     private float ContadorSaltar;
     private float TiempoEstancia = 30.0f;
     public Texture2D[] background;
     public Texture2D[] image;
     public Texture2D[] bar;
     AsyncOperation async;
 
     private void StartLoading(){
         AsyncOperation async = Application.LoadLevelAsync ("Scene1");
         async.allowSceneActivation = false;
         StartCoroutine ("activateScene");
     }
 
     // Update is called once per frame
     void OnGUI () {
         GUI.DrawTexture(new Rect(0,0,Screen.width,Screen.height),background[0]);
         GUI.DrawTexture(new Rect(0,0,Screen.width,Screen.height),image[0], Scale$$anonymous$$ode.ScaleToFit, true);
         GUI.DrawTexture(new Rect(0,Screen.height-Screen.height/100,Screen.width/30*ContadorSaltar,Screen.height/100),bar[0]);
     }
 
     IEnumerator activateScene() {
         ContadorSaltar += 1 * Time.deltaTime;
         if (ContadorSaltar >= TiempoEstancia) {
             async.allowSceneActivation = true;
             yield return async;
         }
     }
     
 }

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

GUITexture touch play animation 0 Answers

how to size the guitexture which with animation on it in different resolutions? 1 Answer

Can I make animations snap to a frame? 1 Answer

Animate GUI Elements 1 Answer

How to select an animation clip by index number? 7 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