Unity process enables object color dynamic switching

Source: Internet
Author: User


public class Changecolor:monobehaviour {
Private Meshrenderer Meshrender;
Use this for initialization
void Start () {
Meshrender = getcomponent<meshrenderer> ();
Startcoroutine (Changecolors ());
}

Update is called once per frame
void Update () {
This.gameObject.transform.Rotate (Vector3.back,800*time.deltatime); Realizing that the object has been rotated around the center

}
IEnumerator changecolors ()
{
Yield return new waitforseconds (0.1f);
MeshRender.material.color = Color.Blue; Blue Red Black tri-color switch
Yield return new waitforseconds (0.1f);
MeshRender.material.color = color.red;
Yield return new waitforseconds (0.1f);
MeshRender.material.color = Color.Black;
Yield return Startcoroutine (Changecolors ());

Yield return new waitforseconds (0.1f);
MeshRender.material.SetColor ("_color", New Color (0.5f,0.8f,1f,1f));
Yield return new waitforseconds (0.1f);
MeshRender.material.SetColor ("_color", New Color (1f, 1f, 1f, 1f));
Yield return Startcoroutine (Changecolors ()); Control color Rgdb value 0-255 corresponds to 0-1



}
}

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.