Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
4
Question by bowditch · Apr 16, 2010 at 06:17 PM · scenescene-loadingloadleveleffecttransition

Can you create transitions between levels using Application.LoadLevel?

I am using the following function to load between multiple scenes

function OnMouseDown(){
    Application.LoadLevel("Level 2");   
}

It works fine, but I was wondering if there was a way to apply transitions (motion effects) between the scenes. Right now the scene changes with a hard cut and it is a little jarring to the player.

Can you do wipes, fades, or other cut effects specifically when switching levels?

Any thoughts are appreciated. Thanks

Comment
Add comment
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

6 Replies

· Add your reply
  • Sort: 
avatar image
-2
Best Answer

Answer by bowditch · Dec 08, 2010 at 12:18 AM

Tornado Twins just released a Transition Pack on UnityPrefabs.com. It is compatible with Unity 2.6 and 3.X

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 aman_jha · Jul 09, 2014 at 02:57 PM 0
Share

I would downvote this if I could because I seriously frown upon answers that require money at all - especially if its $75

avatar image
6

Answer by straydogstrut · Apr 16, 2010 at 06:36 PM

In Unity Game Development Essentials there is an example of fading to white between the main menu and the first level. I'd imagine you can use something similar for other effects. I've amended it myself for creating a black fadeout when the player is caught by an enemy.

In the book, Will creates an empty gameObject in the first level and places the following script on it. When the first level is loaded, a white fade in plays for 3 seconds.

// store a small, repeatable texture (a white square) var theTexture : Texture2D; private var StartTime : float;

function OnLevelWasLoaded(){ // Store the current time StartTime = Time.time; }

function Update(){ // if 3 seconds have passed since the timer was started if(Time.time-StartTime >= 3){ // destroy the gameobject this script is attached to Destroy(gameObject); } }

function OnGUI(){ // set the color of the GUI GUI.color = Color.white;

// interpolate the alpha of the GUI from 1(fully visible) // to 0(invisible) over time GUI.color.a = Mathf.Lerp(1.0, 0.0, (Time.time-StartTime));

// draw the texture to fill the screen GUI.DrawTexture(Rect(0,0,Screen.width, Screen.height), theTexture);

}

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 HolBol · Oct 20, 2010 at 07:38 PM 0
Share

How do i get this to work? I just get a white screen when i use a white texture

avatar image
4

Answer by Tuti · Apr 16, 2010 at 06:49 PM

Scrip taken from the FPS Tutorial: http://unity3d.com/support/resources/tutorials/fpstutorial

/* Usage:

 // Load my level    
 LevelLoadFade.FadeAndLoadLevel("mylevel", Color.white, 0.5);

 // Reset the current level
 LevelLoadFade.FadeAndLoadLevel(Application.loadedLevel, Color.white, 0.5);

*/

static function FadeAndLoadLevel (level, fadeTexture : Texture2D, fadeLength : float) { if (fadeTexture == null) FadeAndLoadLevel(level, Color.white, fadeLength);

 var fade = new GameObject ("Fade");
 fade.AddComponent(LevelLoadFade);
 fade.AddComponent(GUITexture);
 fade.transform.position = Vector3 (0.5, 0.5, 1000);
 fade.guiTexture.texture = fadeTexture;
 fade.GetComponent(LevelLoadFade).DoFade(level, fadeLength, false);

}

static function FadeAndLoadLevel (level, color : Color, fadeLength : float) { var fadeTexture = new Texture2D (1, 1); fadeTexture.SetPixel(0, 0, color); fadeTexture.Apply();

 var fade = new GameObject ("Fade");
 fade.AddComponent(LevelLoadFade);
 fade.AddComponent(GUITexture);
 fade.transform.position = Vector3 (0.5, 0.5, 1000);
 fade.guiTexture.texture = fadeTexture;

 DontDestroyOnLoad(fadeTexture);
 fade.GetComponent(LevelLoadFade).DoFade(level, fadeLength, true);

}

function DoFade (level, fadeLength : float, destroyTexture : boolean) { // Dont destroy the fade game object during level load DontDestroyOnLoad(gameObject);

 // Fadeout to start with
 guiTexture.color.a = 0;

 // Fade texture in
 var time = 0.0;
 while (time < fadeLength)
 {
     time += Time.deltaTime;
     guiTexture.color.a = Mathf.InverseLerp(0.0, fadeLength, time);
     yield;
 }
 guiTexture.color.a = 1;
 yield;

 // Complete the fade out (Load a level or reset player position)
 Application.LoadLevel(level);

 // Fade texture out
 time = 0.0;
 while (time < fadeLength)
 {
     time += Time.deltaTime;
     guiTexture.color.a = Mathf.InverseLerp(fadeLength, 0.0, time);
     yield;
 }
 guiTexture.color.a = 0;
 yield;

 Destroy (gameObject);

 // If we created the texture from code we used DontDestroyOnLoad,
 // which means we have to clean it up manually to avoid leaks
 if (destroyTexture)
     Destroy (guiTexture.texture);

}

Comment
Add comment · Show 2 · 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 Vonnibles · May 14, 2010 at 06:02 PM 0
Share

I can't tell if this works or not.. is there a way to lengthen the fade so I can see?

avatar image _Shockwave · Mar 03, 2013 at 06:08 AM 0
Share

Thank you. This works like a charm. I just needed to declare the type of level (which is int) in the DoFade method.

avatar image
2

Answer by Eric5h5 · Apr 16, 2010 at 06:35 PM

Application.LoadLevel takes one frame to execute, so by definition motion effects are not possible during the load. You can make effects before or after the LoadLevel call though. Unity Pro has LoadLevelAsync, which, as you would expect from the name, is non-blocking.

Comment
Add comment · 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
1

Answer by Tom 10 · Nov 10, 2010 at 05:33 PM

I ran into a problem using the script from the FPS tutorial. The texture that is faded in and out shows UNDER the GUI elements drawn by the scenes.

Apparently all GUI elements drawn inside OnGUI methods display on top of all GUITextures. In order to display the transition texture on top of everything you have to use GUI.DrawTexture instead of the GUITexture component.

Here's a modified version of LevelLoadFade.js that uses GUI.DrawTexture.

NOTE #1: You have to set GUI.depth to something GREATER THAN the value used in this script (-100). Since depth is a static variable, you HAVE to set it back to 0 or whatever in your other OnGUI methods, or they'll all just get drawn at depth -100.

EDIT: I discovered I could use GUI.color to animate the alpha value of the texture without having to change any pixel data, so this script can do custom textures again.

/* Usage:

 // Load my level    
 LevelLoadFade.FadeAndLoadLevel("mylevel", Color.white, 0.5);

 // Reset the current level
 LevelLoadFade.FadeAndLoadLevel(Application.loadedLevel, Color.white, 0.5);

*/ static function FadeAndLoadLevel(level, fadeTexture:Texture2D, fadeLength:float) { if(fadeTexture == null) FadeAndLoadLevel(level, Color.white, fadeLength);

 var fade = new GameObject ("Fade");
 fade.AddComponent(LevelLoadFade);
 fade.GetComponent(LevelLoadFade).DoFade(level, fadeLength, fadeTexture, Color.white, false);

}

static function FadeAndLoadLevel(level, color:Color, fadeLength:float) { color.a = 1; // Make sure the texture is opaque so it will actually cover the scene var fadeTexture = new Texture2D (1, 1); fadeTexture.SetPixel(0, 0, color); fadeTexture.Apply(); DontDestroyOnLoad(fadeTexture);

 var fade = new GameObject ("Fade");
 fade.AddComponent(LevelLoadFade);
 fade.GetComponent(LevelLoadFade).DoFade(level, fadeLength, fadeTexture, color, true);

}

private var _fadeTexture:Texture2D; private var _rect:Rect; private var _color:Color;

function Awake():void { _rect = new Rect(0, 0, Screen.width, Screen.height); _fadeTexture = null; }

function OnGUI():void { if(_fadeTexture != null) { GUI.depth = -100; // Lower depth values display on TOP of higher ones GUI.color = _color; GUI.DrawTexture(_rect, _fadeTexture); } }

function DoFade(level, fadeLength:float, fadeTexture:Texture2D, color:Color, destroyTexture:boolean) { transform.position = Vector3.zero; // Dont destroy the fade game object during level load DontDestroyOnLoad(gameObject);

 // Fadeout to start with
 _color = color;
 _color.a = 0;
 _fadeTexture = fadeTexture;

 // Fade texture in
 var time = 0.0;
 while(time < fadeLength) {
     time += Time.deltaTime;
     _color.a = Mathf.InverseLerp(0, 1, time / fadeLength);
     yield;
 }
 _color.a = 1;
 yield;

 // Complete the fade out (Load a level or reset player position)
 Application.LoadLevel(level);

 // Fade texture out
 time = 0.0;
 while(time < fadeLength) {
     time += Time.deltaTime;
     _color.a = Mathf.InverseLerp(1, 0, time / fadeLength);
     yield;
 }
 _color.a = 0;
 yield;

 _fadeTexture = null;
 Destroy(gameObject);
 if(destroyTexture)
     Destroy(fadeTexture);

}

Comment
Add comment · 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
  • 1
  • 2
  • ›

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Create a break screen effect 0 Answers

cannot access the next scene 1 Answer

Loading bar for NEXT scene/level... 1 Answer

Level Load Display Delay 0 Answers

Load and run scene in background 1 Answer


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