using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ChangeColor : MonoBehaviour
{
private MeshRenderer meshRenderer;
// Use this for initialization
void Start ()
{
meshRenderer = GetComponent<MeshRenderer>();
StartCoroutine(ChangeColors());
}
// Update is called once per frame
void Update ()
{
//实现物体一直绕中心旋转
this.gameObject.transform.Rotate(Vector3.back, 100 * Time.deltaTime);
}
IEnumerator ChangeColors()
{
//蓝 红 黑 黄 四色切换
yield return new WaitForSeconds(1f);
//蓝色
meshRenderer.material.color = Color.blue;
yield return new WaitForSeconds(1f);
//红色
meshRenderer.material.color = Color.red;
yield return new WaitForSeconds(1f);
//黑色
meshRenderer.material.color = Color.black;
yield return new WaitForSeconds(1f);
//黄色
meshRenderer.material.color = Color.yellow;
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());
//控制颜色的RGDB值 0-255对应0-1
}
}
协程实现物体颜色动态切换
最新推荐文章于 2023-04-26 15:49:21 发布