Unity笔记:逐渐改变材质球颜色

private Color a;
public Color b = new Color(0, 55, 255);

void Update () {
    a = GetComponent().material.color;//自身颜色
    if (Input.GetMouseButtonDown(0)) {
        StartCoroutine("Delay");
    }
}

IEnumerator Delay() {
    while(GetComponent().material.color != b)
    {
        GetComponent().material.color = Color.Lerp(a, b, 0.5f * Time.deltaTime);
        yield return 0;
    }
    GetComponent().material.color = new Color(0,55,255);
}

你可能感兴趣的:(Unity笔记:逐渐改变材质球颜色)