ChangColor.cs 508 B

12345678910111213141516171819202122
  1. using UnityEngine;
  2. namespace Rokid.UXR.Demo
  3. {
  4. public class ChangColor : MonoBehaviour
  5. {
  6. Color[] colors = new Color[] { Color.white, Color.yellow, Color.green, Color.red };
  7. int colorIndex = 0;
  8. void Start()
  9. {
  10. }
  11. public void Change()
  12. {
  13. colorIndex++;
  14. if (colorIndex == colors.Length)
  15. colorIndex = 0;
  16. GetComponentInChildren<MeshRenderer>().material.color = colors[colorIndex];
  17. }
  18. }
  19. }