代碼動態更換MeshRenderer的材質Materials
阿新 • • 發佈:2017-10-18
image ima frame bsp etc iou nbsp call mes
public class metrailstest : MonoBehaviour { Material[] m; Material i; public Material[] n; int index = 0; // Use this for initialization void Start() { i = this.GetComponent<MeshRenderer>().material; m = this.GetComponent<MeshRenderer>().materials; }// Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.A)) { index++; if (index % 2 == 0) this.GetComponent<MeshRenderer>().materials = n; else this.GetComponent<MeshRenderer>().materials = m; } } }
效果如下:
代碼動態更換MeshRenderer的材質Materials