Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 8r3nd4n · Jun 23, 2016 at 10:36 PM · materialalphatween

LeanTween alpha materials

@dentedpixel

I am wishing to change the alpha of a gameobjects material using LeanTween. At the moment this can be done via the LeanTween.alpha property and works. However I have a lot of objects that share the same material that I would like to optimise by just changing the materials alpha and it would then apply to all objects using this material.

As it stands I have 3 sets of colored material (red, green, blue) and I store all gameobjects with those color tags into arrays (so redArray has 8 objects, blueArray had 6 and greenArray has 4). The code then needs to loop through each array and change the material alpha of each gameObject. (So 8 calls in the case of red) I would find it much easier to assign the Material to the script and then call LeanTween.alpha(Material, to, time). (Which should just be 1 call)

Is this something that could be added in the future?

Cheers

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
3
Best Answer

Answer by cstlmode · Jun 24, 2016 at 05:02 AM

use this instead
var mat :material; //the material you want to change the color LeanTween.Value(StartColor,EndColor, Time ).setOnUpdate(UpdateMat) ;

function updatemat(MyColor:Color){

mat.color=MyColor;

}

Comment
Add comment · Show 3 · 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 dentedpixel · Jun 24, 2016 at 10:55 AM 0
Share

Yeah, I would go with this answer. Anytime you want to do something pretty custom it can usually be carried out with LeanTween.value.

avatar image 8r3nd4n · Jun 25, 2016 at 06:22 PM 0
Share

Great, that was along the lines that I was looking for. I modified it a bit to get it working with what I want and in C#.

A follow on from this would be the ability to break the tween if the function gets called again before it has finished running. For example, I am wanting the colour to quickly come from low alpha to full alpha, then fade back down. For this, I use an Enumerator and works for the most part. However if I quickly run the function again before it has returned to initial alpha value, it sort of pops.

         $$anonymous$$aterial mats;
         Color blue = new Color(0,86/255,255/255,1);
     Color fadeBlue = new Color(0,86/255,255/255,0.2f);
     void BlueSplash()
     {
         StartCoroutine ("BlueSplashe");
     }
     IEnumerator BlueSplashe()
     {
         LeanTween.value(gameObject, fadeBlue, blue, 0.3f).setOnUpdate( (Color val)=>{ 
             mats.color = val;
         } );
         yield return new WaitForSeconds (0.3f);
         LeanTween.value(gameObject, blue, fadeBlue, 1f).setOnUpdate( (Color val)=>{ 
             mats.color = val;
     }

$$anonymous$$aybe there needs to be a new variable that stores the current val and uses that as the first argument in the value function? Or is there a way to tell Lean Tween to stop all current tweens?

Cheers

avatar image AleNavarro · Mar 16, 2021 at 03:50 PM 0
Share

Thanks a lot cstlmode from 4 years ago :D

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

47 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

Related Questions

change material rendering mode, but don't update material seems in scene at runtime 2 Answers

Shader alpha depth problem? 1 Answer

Black dots when changed the alpha of the material 0 Answers

Texture2D: pixel Specific alpha not working? 4 Answers

Correct Unlit Shader to use when Fading a Material 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