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 B-R-J · Feb 06, 2018 at 03:50 PM · colorcolor changec# tutorialgradient

convert gradient in to color keys

I am trying to change particle color over lifetime gradient by only using C# code. Is it possible to implement a gradient like this using code, without gradient editor? The documentation has one made for Blue->Red gradient, But it is difficult to figure out the below gradient with multiple colors. alt text

untitled.png (5.1 kB)
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 Hellium · Feb 06, 2018 at 04:03 PM

I don't know the exact values, but you will get the idea, nothing difficult. Just retrieve the exact colors and times using the inspector, and tweak them in the code if you want.

 ParticleSystem ps = GetComponent<ParticleSystem>();
 var col = ps.colorOverLifetime;
 col.enabled = true;
 
 Gradient gradiend = new Gradient();
 GradientColorKey[] colorKeys = new GradientColorKey[3];
 GradientAlphaKey[] alphaKeys new GradientAlphaKey[2];
 
 alphaKeys[0].time = 0 ;
 alphaKeys[0].alpha = 1;
 
 alphaKeys[1].time = 1 ;
 alphaKeys[1].alpha = 1;
 
 colorKeys[0].time = 0.079;
 colorKeys[0].color = Color.white;
 
 colorKeys[1].time = 0.15;
 colorKeys[1].color = new Color32(R, G, B);
 
 colorKeys[2].time = 0.5;
 colorKeys[2].color = new Color32(R, G, B);
 
 gradiend.SetKeys(colorKeys, alphaKeys);        
 
 col.color = grad;
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 B-R-J · Feb 17, 2018 at 08:11 AM 0
Share

Got it. Thanx a lot for helping :)

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

75 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

Related Questions

Apply gradient between two colors on x amount of objects 1 Answer

Gradient Background Color,Gradient Background color 0 Answers

When I try to change the Color of an Image, It will change to the original Image color instead.,When I change the color of an Image, it will show the original source image color instead 1 Answer

Why does a button disappear when changing the ColorBlock? 0 Answers

Changing LineRenderer color over time in update 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