• 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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



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

Changing a GUITexture's alpha gives me no effect in game. 0 Answers

Unity 5.2 Canvas.RenderOverlays serious fps hit 2 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges