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
0
Question by Latedi · Mar 02, 2016 at 12:40 PM · uiimagefadefadeoutfadein

Fade in with CrossFadeAlpha

So I think I reversed the meanings, FadeOut being "fade out the players vision" and the opposite for FadeIn. Now, I can make the screen fade from black to normal but not in the other direction. Is there anything wrong with my script or do I just not understand CrossFadeAlpha? The debug log suggests that all parts are being called in the correct order. I'm pretty sure it's a simple mistake somewhere but I cannot figure out what.

 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 
 public class FadeScreen : MonoBehaviour {
 
     private Image Image;
     Color color = Color.black;
 
     // Use this for initialization
     void Start () {
         Image = gameObject.GetComponentInChildren<Image>();
         Disable();
     }
     
     // Update is called once per frame
     void Update () {
     }
 
     public void Disable()
     {
         Debug.Log("Disabling Fade Image");
         Image.enabled = false;
     }
 
     public void Enable()
     {
         Debug.Log("Enabling Fade Image");
         Image.enabled = true;
     }
 
     public void FadeIn(int seconds)
     {
         Debug.Log("FadeIn called");
 
         Enable();
         color.a = 1;
         Image.color = color;
 
         Image.CrossFadeAlpha(0, seconds, false);
     }
 
     public void FadeOut(int seconds)
     {
         Debug.Log("FadeOut called");
 
         Enable();
         color.a = 0f;
         Image.color = color;
 
         Image.CrossFadeAlpha(1, seconds, false);
     }
 }

Comment
Add comment · Show 1
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 NickWu · Mar 02, 2016 at 06:38 PM 0
Share

http://answers.unity3d.com/questions/881620/uigraphiccrossfadealpha-only-works-for-decrementin.html

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Fredex8 · Mar 02, 2016 at 06:31 PM

The unity API says Image.CrossFadeAlpha uses (float alpha, float duration, bool ignoreTimeScale). Your seconds value is an int so it only going to be able to change the alpha value once per second rather than frame by frame.

Why this results in it working one way and not the other I am not sure but you do have color.a = 0f; explicitly defined as a float but none of your other values have the f. I doubt that is causing a problem but they probably should all be written as 1f and 0f.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Fade In / Out UI Image 3 Answers

Fade logo before main menu 2 Answers

[4.6 UI] Image fading - How to? 2 Answers

How do I make the screen fade when it goes into the next level? 0 Answers

Unity 5.2 Canvas.RenderOverlays serious fps hit 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