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
1
Question by melonman · May 25, 2012 at 10:19 AM · texturefadefadeoutfadeinsmoothly

Smoothly Fade in a texture

Hi I am trying to produce a Fade in effect and refine it so that I can fade in a texture alpha using exact increments.

Im mostly there and it seems to make sense however when I use the script to effect the objects texture nothing happens to it's alpha it just automatically pops in at full opacity instead of gradually raising the opacity from 0 - 1.

Here is my code so far.....

using UnityEngine; using System.Collections;

public class Environmental_FX_trigger : MonoBehaviour {

 GameObject environmental_FX_trigger;
 GameObject new_background_plane;
 GameObject blur_background_plane;
 
 
 public float Fade_start_Value;
 
 //public float Fade_end_Value = 1;
 //public float current_Value;
 void Awake ()
     
 {
     environmental_FX_trigger = GameObject.Find("special_FX/environmental_FX_trigger");
     new_background_plane = GameObject.Find("special_FX/environment_background_grp/new_background_plane");
     blur_background_plane = GameObject.Find("special_FX/environment_background_grp/blur_background_plane");
     
     blur_background_plane.SetActiveRecursively(true);
 }
 
 
 
       public void Wait_Fade() {
     StartCoroutine(wait());
     }

     private IEnumerator wait()
     {
         //x starts at zero - next - while x is less than 20 do stuff - next - repeat the "for loop" equation.
         for(int x = 0; x < 20; x++)
         {
             //wait for one second and then add 1 to the Fade_start_Value by the specified increment. 
             yield return new WaitForSeconds(1);
             Fade_start_Value += 0.1f;    
             
             //Declare an instance of the objects color value 
             //Plugin in a numerical increment into the new value's alpha channel. 
             //Then make the original objects color value equal to the instanced value.
             Color fadeColour = blur_background_plane.renderer.material.color;
             fadeColour.a = Fade_start_Value;
             blur_background_plane.renderer.material.color = fadeColour;
         
         
         }
         //Keep the Faade_start_Value at 0 if the Couritine hasn't been activated.
         Fade_start_Value = 0;
         }
 
 
 
 
 void OnTriggerEnter (Collider environmental_FX_trigger)
     
 {
     //  1. When entering the trigger change blur texture over time (fade in).
     Wait_Fade();
     
     print("IN TRIGGER NOW!!!!!");
     blur_background_plane.SetActiveRecursively(true);
 
 }
 
 void OnTriggerExit (Collider environmental_FX_trigger)
     
 {
     //  1. When entering the trigger change blur texture over time (fade out).
     print("OUT TRIGGER NOW!!!!!");
 }
 /*
 //----------------------------------------
   if (Patient_choice_GUI_Skin != null)
     {
         if(showPatientChoiceGUI)
             {    
             GUI.skin = Patient_choice_GUI_Skin;
             
             Color patientChoice_newAlpha = GUI.color;
             patientChoice_newAlpha.a = patientChoice_thisColor * patientChoice_InTransition;
             GUI.color = patientChoice_newAlpha;
             print("working");
             {    
             if(Time.time < 6f)
             {
                 patientChoice_InTransition = 0.2f * Time.time;
             }
             else if(Time.time > 6f)
             {
                 patientChoice_InTransition = 1f;
             }
             }    
 
 //----------------------------------------
 */
 
 
 
 

}

Where am I going wrong?

Comment
Add comment · Show 3
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 Eric5h5 · May 25, 2012 at 11:11 AM 1
Share

http://unifycommunity.com/wiki/index.php?title=Fade

avatar image flamy · May 25, 2012 at 11:14 AM 0
Share

@karl take a look at the link posted by eric, that has helped me in numerous occasions :)

avatar image melonman · May 25, 2012 at 12:07 PM 0
Share

Thanks Erich5h5 and flamy will check this out and see what I come up with.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Wolfram · May 25, 2012 at 10:49 AM

One reason could be that your Coroutine is triggered several times. Since you don't reset Fade_start_Value at the beginning of your coroutine, each simultaneously active coroutine adds 0.1 to the alpha each second.

Do you get your "IN TRIGGER NOW!!!!!" message once or several times?

Comment
Add comment · Show 6 · 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 melonman · May 25, 2012 at 12:09 PM 0
Share

No the msg only comes up once whenever I enter the trigger area if I go back out and then re-enter it shows again once so maybe I need to use on TriggerStay or something like that is that where Im going wrong?

avatar image melonman · May 25, 2012 at 12:59 PM 0
Share

Okay I checked out your link Eric5h5 and copied the following code replacing the object in question for the Fade with my own the code is as follows now in c#.....

public class Fade : $$anonymous$$onoBehaviour {

   void Start () 
     {
     Fade.use.StartCoroutine(blur_background_plane, 0.0, 1.0, 5.0f, EaseType.InOut);
    // StartCoroutine(Fade.use.Alpha(.renderer.material, 0, 1.0, 3.0f, EaseType.InOut));
     }

}

I seem to get the following errors up however....

ERROR_1

Assets/Standard Assets/Scripts/Fade.cs(10,22): error CS0117: Fade' does not contain a definition for use'

avatar image Wolfram · May 25, 2012 at 01:16 PM 0
Share

No, you need to copy the whole script at the bottom of the Wiki page into a script named "Fade.js". Then you can use Fade.use.whatever from your own scripts.

avatar image Wolfram · May 25, 2012 at 01:20 PM 0
Share

I presume you do use one of the "Transparent" shaders for your blur_background_plane object?

avatar image melonman · May 29, 2012 at 01:08 PM 0
Share

Thanks Wolfram.

I tweaked added all the script and now have the new function of fade.

I have implemented a new script with the following code ......

void OnGUI () {

     if(Event.current.type == EventType.keyUp && Event.current.keyCode == $$anonymous$$eyCode.L)
         
     {
     //Fade.use.StartCoroutine(renderer.material.color.a, 0, 1, 5.0f, EaseType.InOut);
     Fade.use.Alpha(this.renderer.material.color.a, 1, 0, 20f, EaseType.InOut);
     }    
 }
 

}

The script seems to be fine and does make something happen (as follows)..

In the inspector view when I attach my script to said game object, as soon as the script is invoked the material preview box appears at the bottom right of the inspector, so I know something is happening.

However still no luck with fading in and out as far as the alpha goes the plane with the texture I want to fade in and out doesn't change a bit in my game view?

Any ideas as to what might be happening?

Show more comments

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Fade In / Out UI Image 3 Answers

Fade out sprite on click 4 Answers

How can I fade in/out an object nonstop automatic ? 2 Answers

Fade logo before main menu 2 Answers

Sprite smooth fade out/in 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