• 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 Lonasora · Jul 13, 2017 at 08:44 PM · triggerimageimage effectsfading

My image does not get transparent all the way!

Hello!

Mm having some trouble to get my image transparent all the way, when my character goes on a trigger collider a image should pop up and the disappear when exiting the trigger but when exiting the trigger the image has an alpha of 4, but sometimes it does go down to 0 but i dont know why it somtimes does not go down all the way to 0.

Here is my code for the trigger. (fading code is in the end )

 using System.Collections;
 using UnityEngine;
 using UnityEngine.UI;
 
 public class jump_triggers : MonoBehaviour
 
 
 {
   
     public bool onTrigger;
     public Image img;
     public Canvas Canvas_use;
     public Transform player;
    static int y; // trigger once
 
     
     private void Awake()
     {
       
         Canvas_use.enabled = false;
 
     }
 
     // when entring the collider show the canvas
     void OnTriggerEnter(Collider coll)
     {
         if (coll.gameObject.tag == "Player" && y == 0)
         {
             onTrigger = true;
             Canvas_use.enabled = true;
             Debug.Log("test");
             StartCoroutine(FadeImage(false));
         }
         else
         {
             Canvas_use.enabled = false;
         }
     }
 
     //when exiting the collider change to default
     void OnTriggerExit(Collider coll)
     {
 
         if (coll.gameObject.tag == "Player" && y == 0)
         {
             onTrigger = false;
             Canvas_use.enabled = true;
             StartCoroutine(FadeImage(true));
         }
         else
         {
 
             Canvas_use.enabled = false;
         }
         y++; // trigger once
     }
     IEnumerator FadeImage(bool fadeAway)
     {
         // fade from opaque to transparent
         if (fadeAway)
         {
             // loop over 1 second backwards
             for (float i = 3; i >= 0; i -= Time.deltaTime) // fade speed (i)
             {
                 // set color with i as alpha
                 img.color = new Color(1, 1, 1, i);
                 yield return null;
             }
         }
         // fade from transparent to opaque
         else
         {
             // loop over 1 second
             for (float i = 0; i <= 1; i += Time.deltaTime)
             {
                 // set color with i as alpha
                 img.color = new Color(1, 1, 1, i);
                 yield return null;
             }
         }
     }
 }
 
 




















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

Answer by Mercbaker · Jul 13, 2017 at 08:52 PM

You should log what (3-Time.deltaTime) returns and you will get your answer as to why your image is not fading away.

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

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

83 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

Related Questions

Shader in SpriteRenderer vs UI Image 0 Answers

Image appears in scene tab but not in game tab 1 Answer

How do I trigger GUI elements 1 Answer

OpenCV Sharp and Unity help (making detected facial features interactive) 1 Answer

Enabeling components 1 Answer


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