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; } } }
效果如下: