- Home /
Animate tint > alpha?
I need help. Im trying to animate my particle systems tint color's alpha channel. I know how to animate the color.....
renderer.material.SetColor ("_TintColor", Color);
But I want to animate the alpha, not the color. Can anyone please help me with this? Thanks for any help.
Answer by sethuraj · May 04, 2015 at 12:25 PM
The color class includes an alpha value
Color(float Red,float Green,float Blue,float Alpha) each value ranges from 0 to 1.0
//Get the current color
Color OriginCol = renderer.material.GetColor ("_TintColor", Color);
//Modify the Alpha Or use Lerp() or what ever you want to change this value
OriginCol.a=0.5f;
//Reassign the color with the new alpha
renderer.material.SetColor ("_TintColor", OriginCol);
Good Luck...
Thanks for that Sethuraj.
I may have not been clear enough though. I am trying to animate the alpha channel with random values. So for each frame of time, the alpha should be a different value. Any help appreciated. Thanks again for any and all help! :D
The update function is called once perframe.So for each frame you need different alpha value use the Random Class
In the above code use
OriginCol.a = Random.range(0.0f,1.0f);
But changing the alpha to random value for every frame will give a fast and wierd effect like flickering.If your game fps is 60 then the alpha will have 60 random values every second.Try assigning a random value every 1sec or more which will make the effect more visible.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Change skybox color via script? 0 Answers
Setting texture for a transparent material in c# 0 Answers
Unity Meshes for C# generated objects 0 Answers