• 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
Question by CiberX15 · Feb 25, 2014 at 10:28 PM · materialcolorrendereralphaprogrammatically

Fade out a material that has a texture

Ok what I am asking for is fairly simple however it is giving me problems. I have also seen similar questions asked but none of the suggestions have worked for me. I am trying to create a shock wave that expands outwards then fades away programaticaly. I am using this code:

 var Dammage : float = 1;        //How much dammage the projectile does on impact;
 var Speed : float = 1;            //How fast does the projectile move
 var Lifetime : float = 10;        //How long does the projectile last
 
 
 private var TimePassed : float = 0;
 
 function Update () 
 {
     transform.localScale += Vector3(Speed,Speed,Speed);
     TimePassed += Time.deltaTime;
     if(TimePassed >= Lifetime / 2)
     {
         //Fade Material
         renderer.material.color.a = 1 - 1 * TimePassed / Lifetime;
         Debug.Log("Should fade");
     }
     
     if(TimePassed >= Lifetime)
     {
         Destroy(gameObject);
     }
 }

This does not throw up any errors in the compiler nor at run-time, however it also has no effect. The material I am using is a "Unlit/Transparent" so it does have an alpha channel. However, it does also have a texture assigned to it that has its own alpha settings. Is there something special I need to do to get a material to fade out when it has a texture, or am I just doing something wrong?

Thanks in advance for the help : )

Comment
naviln

People who like this

1 Show 0
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
Best Answer

Answer by robertbu · Feb 25, 2014 at 10:45 PM

You need a shader that 1) supports transparency and 2) has an Color property. Unlit/Transparent does not have an Color property, so setting the alpha value in the color does nothing. I use a shader that came with another package for what you are doing here, but I believe this shader from the Wiki should do the job:

http://wiki.unity3d.com/index.php/UnlitAlphaWithFade

Also Unity's Diffuse shader has a Color property, so you can start by using that and put a directional light in the scene just to get your code working.

[1]: http://wiki.unity3d.com/index.php/AlphaSelfIllum

Comment
SinisterRainbow
CiberX15
naviln

People who like this

3 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 CiberX15 · Feb 26, 2014 at 02:45 AM 0
Share

Thank you that fixed it.

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.

Update about the future of Unity Answers

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta later in June. Please note, we are aiming to set Unity Answers to read-only mode on the 31st of May in order to prepare for the final data migration.

For more information, please read our full announcement.

Follow this Question

Answers Answers and Comments

20 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

Related Questions

Changing two different objects renderer colour 1 Answer

Material doesn't have a color property '_Color' 4 Answers

Renderer.material not cloning? 3 Answers

render.material.color is not working, or at least not completely? 1 Answer

I'm trying to change a material, texture or color and it doesnt work 0 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