美文网首页
unity中获取所有子物体上的material并渐变颜色

unity中获取所有子物体上的material并渐变颜色

作者: Moment__格调 | 来源:发表于2016-12-18 01:32 被阅读944次
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);
        } 

    }
}
Paste_Image.png

相关文章

网友评论

      本文标题:unity中获取所有子物体上的material并渐变颜色

      本文链接:https://www.haomeiwen.com/subject/mtpamttx.html