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 /
  • Help Room /
avatar image
0
Question by KarloBRIK · Mar 22, 2017 at 01:22 PM · scenemenufadesplash-screenfade out

I have New Game text/button in my Canvas/Scene and I want when I click New Game to fade out! READ MORE!

So I want when I click on New Game to slowly fade out. Now also I have a background music playing. I'd like to fade out the music with the screen. And then when the screen faded out I need to switch to my scene that only has black plane and that plane is there to create different images appear. For example my "studio" name BlackPanther. So I want BlackPanther to appear and then disappear slowly and then word "Presents" to appear slowly and disappear slowly and some other texts/logos/images. And then my "firstscene" starts. I made animation, so That will work. But in general I need fade out; and maybe if someone is kind to help - I'd give you credits in my game.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by PPenar · Mar 22, 2017 at 02:30 PM

Attach this script to any GameObject, drag the button or any other canvas element to the CanvasRenderer field. Call StartCanvasFadeOut() on a button click to fade out only 1 element and StartCanvasFamilyFadeOut() to fade out whole family of Canvas Renderers using System.Collections; using UnityEngine;

 public class FadeOutEffect : MonoBehaviour
 {
     [SerializeField]
     private CanvasRenderer canvasRenderer;
     [SerializeField]
     float fadeTime = 1;
     [SerializeField]
     bool fadeOnStart;
 
     void Start()
     {
         if (fadeOnStart)
         {
             StartCanvasFamilyFadeOut();
         }
     }
 
     public void StartCanvasFadeOut()
     {
         if (canvasRenderer != null)
         {
             StartCoroutine(CanvasFadeOut(canvasRenderer));
         }
     }
 
     public void StartCanvasFamilyFadeOut()
     {
         if (canvasRenderer != null)
         {
             StartCoroutine(CanvasFamilyFadeOut(canvasRenderer));
         }
     }
 
     IEnumerator CanvasFadeOut(CanvasRenderer targetCanvas)
     {
         float currentTime = fadeTime;
         while (currentTime > 0)
         {
             targetCanvas.SetAlpha(currentTime / fadeTime);
             currentTime -= Time.deltaTime;
             yield return null;
         }
     }
 
     IEnumerator CanvasFamilyFadeOut(CanvasRenderer parentCanvas)
     {
         float currentTime = fadeTime;
         CanvasRenderer[] canvasRenderers = parentCanvas.GetComponentsInChildren<CanvasRenderer>();
         while (currentTime > 0)
         {
             foreach (CanvasRenderer canvasRenderer in canvasRenderers)
             {
                 canvasRenderer.SetAlpha(currentTime / fadeTime);
             }
             currentTime -= Time.deltaTime;
             yield return null;
         }
     }
 }
 
Comment
Add comment · Show 3 · 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 KarloBRIK · Mar 22, 2017 at 04:39 PM 0
Share

Okay thanks. So what happens to me now, only New Game Text/button disappears, not the screen. But what I don't understand is this

"and StartCanvasFamilyFadeOut() to fade out whole family of Canvas Renderers using System.Collections; using UnityEngine;"

Where do I put this... In the same button? You can answer me, but in the mean time I will try to fix this.

avatar image PPenar · Mar 22, 2017 at 06:39 PM 0
Share

@$$anonymous$$arloBRI$$anonymous$$ You can launch either function - depending if you want to fade out multiple UI elements in the same time or only one. If you want to fade out the whole scene to - let's say - black colour, you can put black panel on screen overlay canvas, and reverse the process - ins$$anonymous$$d of decreasing alpha, increase it

avatar image KarloBRIK PPenar · Mar 22, 2017 at 07:06 PM 0
Share

Well to be honest, I only want screen to go black slowly and the sound with it. And then Load another scene that has the black plane and then do the splash things. But I'll try to do this now and see if it works.

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

103 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 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 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 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 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 avatar image avatar image avatar image

Related Questions

What's the easiest way to fade a sprite in? - Looking for equiv of jQuery's fadeIn() 0 Answers

Help with main menu 0 Answers

How to Restart game (Menu and Game are in same Scene)? 1 Answer

How to disable Splash Screen fade to Scene? 1 Answer

Menu question: Separate Scene or Canvas overlay? 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