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 Neefy · Mar 03, 2013 at 01:06 AM · triggerplayerlevelfadecollsion

Level Fade Help!

Hello world! I've been trying to figure this out but no luck as of yet :( So basically, I want the level to load and fade-in as the character walks into the box collider. This is what I've managed to create so far and do not know how to do the fade transition. Any help would be greatly appreciated! Thank's in advance. (Oh and I am new to scripting)

 using UnityEngine;
 using System.Collections;
 
 public class LevelTrigger : MonoBehaviour {
 void  OnTriggerEnter ( Collider cubeTrigger  ){   
     Debug.Log ("OnTriggerEnter : cubeTrigger.tag = " + cubeTrigger.tag); // shows the tag of the trigger
     // if tag is player
     if (cubeTrigger.tag == "Player")
     {
        var firstlevel = GameObject.Find("Level1");
        Destroy(firstlevel);
        Application.LoadLevelAdditiveAsync ("Level2"); 
     }
 }
 }    
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Bunny83 · Mar 03, 2013 at 01:11 AM

So you want something like this:

http://answers.unity3d.com/questions/119918/transitions-between-changing-scenes.html#answer-119951

or do you talk about something else? If you want to fade "the whole scene" the easiest way would be to render both to a texture and fade the fullscreen textures. If you don't have Unity pro this is "almost" impossible. You could try to replace all shaders on all renderers and fade the materials alpha values. That's probably quite slow and might not give the right result.

A bit more detail on what you actually mean by "fading" and if you have Unity pro available or not would be nice-

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 Neefy · Mar 03, 2013 at 01:33 AM 0
Share

Oh wow, this is exactly what I want! I happened to pass by this thread a few hours ago and gave it a go but it did not work. I mean when I click play, nothing happens (grey screen). No error though. Oh and I am using Unity Pro 3.5.6f4 by the way. Here's the script...

 using UnityEngine;
 using System.Collections;
 
 public class LevelTrigger : $$anonymous$$onoBehaviour {
 void  OnTriggerEnter ( Collider cubeTrigger  ){   
     Debug.Log ("OnTriggerEnter : cubeTrigger.tag = " + cubeTrigger.tag); // shows the tag of the trigger
     // if tag is player
     if (cubeTrigger.tag == "Player")
     {
        var firstlevel = GameObject.Find("Level1");
        Destroy(firstlevel);
        AutoFade.LoadLevelAdditiveAsync ("Level2" ,3,1,Color.black); 
     }
 }
 }    





 // AutoFade.cs
 using UnityEngine;
 using System.Collections;
  
 public class AutoFade : $$anonymous$$onoBehaviour
 {
     private static AutoFade m_Instance = null;
     private $$anonymous$$aterial m_$$anonymous$$aterial = null;
     private string m_LevelName = "";
     private int m_LevelIndex = 0;
     private bool m_Fading = false;
  
     private static AutoFade Instance
     {
         get
         {
             if (m_Instance == null)
             {
                 m_Instance = (new GameObject("AutoFade")).AddComponent<AutoFade>();
             }
             return m_Instance;
         }
     }
     public static bool Fading
     {
         get { return Instance.m_Fading; }
     }
  
     private void Awake()
     {
         DontDestroyOnLoad(this);
         m_Instance = this;
         m_$$anonymous$$aterial = new $$anonymous$$aterial("Shader \"Plane/No zTest\" { SubShader { Pass { Blend SrcAlpha One$$anonymous$$inusSrcAlpha ZWrite Off Cull Off Fog { $$anonymous$$ode Off } BindChannels { Bind \"Color\",color } } } }");
     }
  
     private void DrawQuad(Color aColor,float aAlpha)
     {
         aColor.a = aAlpha;
         m_$$anonymous$$aterial.SetPass(0);
         GL.Color(aColor);
         GL.Push$$anonymous$$atrix();
         GL.LoadOrtho();
         GL.Begin(GL.QUADS);
         GL.Vertex3(0, 0, -1);
         GL.Vertex3(0, 1, -1);
         GL.Vertex3(1, 1, -1);
         GL.Vertex3(1, 0, -1);
         GL.End();
         GL.Pop$$anonymous$$atrix();
     }
  
     private IEnumerator Fade(float aFadeOutTime, float aFadeInTime, Color aColor)
     {
         float t = 0.0f;
         while (t<1.0f)
         {
             yield return new WaitForEndOfFrame();
             t = $$anonymous$$athf.Clamp01(t + Time.deltaTime / aFadeOutTime);
             DrawQuad(aColor,t);
         }
         if (m_LevelName != "")
             Application.LoadLevelAdditiveAsync(m_LevelName);
         else
             Application.LoadLevelAdditiveAsync(m_LevelIndex);
         while (t>0.0f)
         {
             yield return new WaitForEndOfFrame();
             t = $$anonymous$$athf.Clamp01(t - Time.deltaTime / aFadeInTime);
             DrawQuad(aColor,t);
         }
         m_Fading = false;
     }
     private void StartFade(float aFadeOutTime, float aFadeInTime, Color aColor)
     {
         m_Fading = true;
         StartCoroutine(Fade(aFadeOutTime, aFadeInTime, aColor));
     }
  
     public static void LoadLevelAdditiveAsync(string aLevelName,float aFadeOutTime, float aFadeInTime, Color aColor)
     {
         if (Fading) return;
         Instance.m_LevelName = aLevelName;
         Instance.StartFade(aFadeOutTime, aFadeInTime, aColor);
     }
     public static void LoadLevelAdditiveAsync(int aLevelIndex,float aFadeOutTime, float aFadeInTime, Color aColor)
     {
         if (Fading) return;
         Instance.m_LevelName = "";
         Instance.m_LevelIndex = aLevelIndex;
         Instance.StartFade(aFadeOutTime, aFadeInTime, aColor);
     }
 }
avatar image
0

Answer by Propagant · Sep 15, 2015 at 11:03 AM

Hey! I made easiest method of AutoFade in unity by Unity Game engine, UI elemets etc... You can free download it here... Fully explained and showed. Enjoy and thanks, if any opinions, just write. AutoFadeAlternative by matt


autofadealternative.zip (3.8 kB)
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

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

11 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

Related Questions

Distance destroy object 3 Answers

How to make volume continually go down in C#Script ? 1 Answer

Moving player in an arc, from startPoint to endPoint 2 Answers

Patrolling AI doesn't see player if it's standing still 1 Answer

Score Question Java Script, problem 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