unity中获取所有子物体上的material并渐变颜色
using System.Collections;
public class BBB : MonoBehaviour {
public float sp = 0.4f;
Material mat;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
foreach (Transform child in gameObject.transform)
{
//Debug.Log("所有该脚本的物体下的子物体名称:"+child.name);
mat = child .GetComponent<MeshRenderer>().material;
//mat.color = Color.blue;
Color col = mat.GetColor("_TintColor");
col.a = Mathf.Lerp(col.a,0, Time.deltaTime*sp);
mat.SetColor("_TintColor",col);
}
}
}
![](https://img.haomeiwen.com/i1771334/fb21496cabd7ded7.png)
Paste_Image.png
本文标题:unity中获取所有子物体上的material并渐变颜色
本文链接:https://www.haomeiwen.com/subject/mtpamttx.html
网友评论