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
2
Question by el-RERS · Aug 31, 2014 at 03:36 AM · guifade4.6

making a fadeout with the new GUI in 4.6?

I figured that making a fadeout transition with the new GUI system would be easy, my plan was: create a black panel (Image component) that fills the whole screen, control the alpha with a Mathf.Lerp and there! fadeout accomplished!.... the problem is, I have no idea how to access the alpha of the Image Component... is there a way to do that? or maybe an even easier way to do fadeouts/fadeins with this new Gui system? thanks in advance!

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

3 Replies

· Add your reply
  • Sort: 
avatar image
7

Answer by Stardog · Dec 20, 2014 at 12:22 AM

Use a CanvasGroup component on the parent panel (not the Image), and fade the Alpha of that.

 using UnityEngine;
 using System.Collections;
 
 public class GUIFadeScript : MonoBehaviour {
 
     public CanvasGroup fadeCanvasGroup;
 
     public IEnumerator FadeToBlack(float speed)
     {
         while (fadeCanvasGroup.alpha < 1f)
         {
             fadeCanvasGroup.alpha += speed * Time.deltaTime;

             yield return null;
         }
     }
 
 }
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 Kiwasi · Dec 20, 2014 at 01:46 AM 1
Share

Here is a video showing the concept

avatar image chrissung · Jan 24, 2015 at 05:05 PM 0
Share

Adding CanvasGroup component to any parent UO container and manipulating its alpha seems to be the way to go for fading in/out, or swapping objects in general

avatar image
1

Answer by kacyesp · Aug 31, 2014 at 03:39 AM

You should use the gui element's color field. color.a represents the alpha value, so that's what you should change.

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 BMayne · Aug 31, 2014 at 03:40 AM 2
Share

$$anonymous$$acyesp beat me to the punch. I will just add one more point.


I would suggest using a canvas group to do fading since the alpha of an image does not always animate well.

Regards,

avatar image
0

Answer by el-RERS · Aug 31, 2014 at 04:00 AM

Thanks a lot! but when using this code:

myImage.color = new Color(0.0f, 0.0f, 0.0f, Mathf.Lerp(myImage.color.a, 0.0f, 255f * Time.deltaTime));

I'm getting this error: "Object Reference not set to an instance of an object" what's up with that? :(

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 kacyesp · Aug 31, 2014 at 04:01 AM 0
Share

myImage probably wasn't initialized.

avatar image BMayne · Aug 31, 2014 at 04:02 AM 0
Share

You have to have an image. I just used myImage as an example. You can get the image component by going

 Image myImage = GetComponent<Image>();
 myImage.color = new Color(0.0f, 0.0f, 0.0f, $$anonymous$$athf.Lerp(myImage.color.a, 0.0f, Time.deltaTime));

Also colours are between 0 - 1 not 0 - 255. Just a heads up :)

avatar image el-RERS · Aug 31, 2014 at 04:03 AM 0
Share

well, I did put this:

void Awake(){ myImage = GetComponent ();

 }

is that what you meant? thanks in advance.

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

26 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

Related Questions

fade in out multi images then go to next scene 1 Answer

Unity 4.7 - OnGUI prevent click/touch through 0 Answers

4.6 GUI Button inside a scrolling Text Box 0 Answers

Fade In GUI on proximity 1 Answer

IPointerClickHandler error 2 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