Monkey original, welcome reprint. Reproduced please specify: Reproduced from COCOS2DER-CSDN, thank you!
Original address: http://blog.csdn.net/cocos2der/article/details/48372999
Fine Arts in the production of particle effects need to be able to modify the particles in some moments flashing, see the next found no settings can be implemented, so add a script to the art use.
The principle is that the art can control render to modify the color of the image
usingUnityengine;usingSystem.Collections; Public classParticleblink:monobehaviour { Public floatStartblinktime =0.0F Public floatBlinkframetime =0.02F Publiccolor[] Blinkcolor =Newcolor[]{NewColor (255.0F255.0F255.0F0.0f),NewColor (255.0F255.0F255.0F255.0f)};PrivateMaterial m_material;Private floatM_blinklifetime =0.0FPrivate BOOLM_isstartblink =false;Private intM_blinkcolorindex =0;// Use this for initialization voidStart () {m_material = Getcomponent<renderer> (). Material; M_blinklifetime =0;if(Startblinktime >0) {M_isstartblink =false; Invoke ("Startblink", startblinktime); }Else{M_isstartblink =true; } }//Update is called once per frame voidUpdate () {if(M_isstartblink) {UpdateColor (); } }voidUpdateColor () {if(Blinkcolor = =NULL|| Blinkcolor.length <=0) {return; } M_blinklifetime + = Time.deltatime;if(M_blinklifetime >= Blinkframetime) {M_blinklifetime =0;//Render material use a different shader, where the color variable name needs to be modifiedM_material.setcolor ("_color", Blinkcolor[m_blinkcolorindex]); M_blinkcolorindex + =1;if(M_blinkcolorindex >= blinkcolor.length) {M_blinkcolorindex =0; } } }voidStartblink () {M_isstartblink =true; }}
- Start Blink time: When to switch color
- Blink Frame Time: How long each color is kept
- Blink color: array of color to switch
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Unity modifies particles Render Material (Unity3d development 23)