Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
8
Question by Doodlemeat · Aug 28, 2014 at 01:49 PM · uicanvasalphapanel

Unity UI - Fading Canvas/Panel

Hello.

I have setup a canvas with a panel inside as a container. And in the panel I have 4 buttons, 1 text label and 1 image and when I press the start button I want to whole UI to fade away so that the game can start. But I have no idea on how to do that. I think I must use CanvasRenderer.SetAlpha() but the Canvas elements doesn't have it.

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

8 Replies

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

Answer by Rs · Feb 09, 2015 at 04:03 PM

If you want to fade colors and alphas using the new UI system (above v4.6) these methods will help:

CrossFadeColor

CrossFadeAlpha

You can use them on any Image component. Example:

 panel.GetComponent<Image>().CrossFadeColor(Color.black, 2.0f, false);
 thatButton.GetComponent<Image>().CrossFadeAlpha(0.1f, 2.0f, false);

Hope this helps.

RS


Important

Note moreover that you can set the alpha of most (all?) UI components like this:

 public Image im;
 im.GetComponent<CanvasRenderer>().SetAlpha(0.5f);

(It's easy to forget an Image already has a CanvasRenderer by default; you don't need to wrap it into one.)

So to "fade in" an Image ...

 im.GetComponent<CanvasRenderer>().SetAlpha(0.1f);
 im.CrossFadeAlpha(1f,.1f,false);


Does NOT do children...

For better or worse this ONLY literally fades that image, not children.

If need to fade "everything below" ....

http://answers.unity3d.com/answers/864600/view.html

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
9

Answer by J_Lepage · Nov 22, 2016 at 09:05 AM

Would adding a Canvas group not be a simpler method to this ? https://docs.unity3d.com/Manual/class-CanvasGroup.html

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 calurin · Feb 07, 2020 at 02:57 PM 1
Share

I know this is an old post, but this answer is the most useful today, and needs to be up-voted. It saved me a lot of redundant code.

avatar image
1

Answer by Landern · Aug 28, 2014 at 01:59 PM

Go watch the new UI tutorials, they cover this in the first couple, though it is referring to the button color, but same concept, different object type.

http://unity3d.com/learn/tutorials/modules/beginner/ui

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
0

Answer by sebastiansgames · Mar 04, 2015 at 05:52 AM

Was just trying to figure out how to fade out just a panel. Ended up here... if anyone else is curious: you need to include 'UnityEngine.UI' at the top of your code. Then access the panel's 'Image':

 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 
 public class myFadePanelClass : MonoBehaviour
 
 {
     public Image myPanel;
     float fadeTime = 3f;
     Color colorToFadeTo;
 
 
     void Start() {
         colorToFadeTo = new Color (1f, 1f, 1f, 0f);
         myPanel.CrossFadeColor (colorToFadeTo, fadeTime, true, true);
     }
 
 }
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
0

Answer by SeasiaInfotechind · Apr 27, 2015 at 04:57 AM

Hello Doodlemeat,

For FadeIn/Out effect you could use:-

FadeIn YourPanel.color = new Color (0.0f, 0.0f, 0.0f, Mathf.Lerp (YourPanel.color.a, 0.0f, Time.deltaTime * 1.1f));

FadeOut YourPanel.color = new Color (0.0f, 0.0f, 0.0f, Mathf.Lerp (YourPanel.color.a,235/255f, Time.deltaTime * 1.1f));

Thank You.

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 YanHoxley · May 18, 2015 at 05:50 AM 0
Share

(45,66): error CS1526: A new expression requires () or [] after type

  • 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

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

UI Fading in flicker 5.5 1 Answer

[CanvasGroup] alpha on children as combined (merged) texture? 1 Answer

Why do contents of nested Panel spill outside parent? 0 Answers

3d object between two uipanel 1 Answer

Keeping relative size of UI elements without moving them 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