Unity modifies particles Render Material (Unity3d development 23)

Source: Internet
Author: User

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; }}

    1. Start Blink time: When to switch color
    2. Blink Frame Time: How long each color is kept
    3. 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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.