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

2016-12-18  本文已影响944人  Moment__格调
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
上一篇 下一篇

猜你喜欢

热点阅读