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
0
Question by Maffew · Mar 07, 2015 at 01:17 AM · unity 5

Unity 5 material alpha

Hi all,

I'm trying to set material alphas in the project window through a C# editor script. I manage to set it to the value I want using SetColor("_Color",newColor) and it shows up correctly in the inspector, however, it doesn't update in the scene. If I then change ANY value in the inspector it updates the alpha setting. I have tried setting the material as dirty and doing an AssetDatabase.Refresh() but it doesn't seem to work. Nor does it update when saving the project, closing unity and reopening. There must be something I'm missing but I can't work out what. Any help would be much appreciated.

Thanks,

Matt

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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by xCiter · Mar 07, 2015 at 03:35 AM

Hey there,

I've been trying to do what I think you're trying to do.

First, I set the shader of the object to "Legacy Shaders > Transparent > Diffuse"

Then in a script attached to the game object, I did...

     public float alpha;
     public Color colourPicker = new Color (0.5f, 0.5f, 0.5f);
 
     // Use this for initialization
     void Start () {
         colourPicker.a = colourPicker.a - alpha;
         this.gameObject.GetComponent<MeshRenderer> ().material.SetColor ("_Color", colourPicker);

In the inspector, I set the colour picker alpha to 255 to start with. If you use this script, just change the Alpha float variable between 0 ( no transparency ) and 1 (see-through)

Hope this helps...I'm sure someone will come along and have a better way. But if not, I hope this serves you for now :)

Comment
Add comment · 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 jerry2157 · Jul 27, 2016 at 05:54 AM 0
Share

thank you, it works!!!

avatar image
0

Answer by Maffew · Mar 09, 2015 at 03:12 PM

Unfortunately this didn't help :(

My solution in the end was to put all transparent materials to an array then use Selection.objects to select them in the project window then manually change the value of one of the common variables in the inspector window, in my case the tiling offset.

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
avatar image
0

Answer by GLeBaTi · Feb 02, 2016 at 08:16 AM

 renderer.material.SetFloat("_Mode", 3);
         renderer.material.color = GameHelper.SetAlpha(renderer.material.color, 0.5f);
 
 
         renderer.material.SetOverrideTag("RenderType", "Transparent");
         renderer.material.SetInt("_SrcBlend", 1);
         renderer.material.SetInt("_DstBlend", 10);
         renderer.material.SetInt("_ZWrite", 0);
         renderer.material.DisableKeyword("_ALPHATEST_ON");
         renderer.material.DisableKeyword("_ALPHABLEND_ON");
         renderer.material.EnableKeyword("_ALPHAPREMULTIPLY_ON");
         renderer.material.renderQueue = 3000;
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

Gradle is failed to fetch dependencies , admob ,in UNITY console , Gradle failed to fetched dependencies 3 Answers

Unable to generate offline license for Unity 5.4 installation 0 Answers

How To make a Ui button Chance colours when pressed 1 Answer

GetKeyDown held for too long 1 Answer

How to check if game was started once 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