MaterialPropertyBlockExample.cs 749 B

123456789101112131415161718192021222324252627282930313233
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace Spine.Unity.Examples {
  5. public class MaterialPropertyBlockExample : MonoBehaviour {
  6. public float timeInterval = 1f;
  7. public Gradient randomColors = new Gradient();
  8. public string colorPropertyName = "_FillColor";
  9. MaterialPropertyBlock mpb;
  10. float timeToNextColor = 0;
  11. void Start () {
  12. mpb = new MaterialPropertyBlock();
  13. }
  14. void Update () {
  15. if (timeToNextColor <= 0) {
  16. timeToNextColor = timeInterval;
  17. Color newColor = randomColors.Evaluate(UnityEngine.Random.value);
  18. mpb.SetColor(colorPropertyName, newColor);
  19. GetComponent<MeshRenderer>().SetPropertyBlock(mpb);
  20. }
  21. timeToNextColor -= Time.deltaTime;
  22. }
  23. }
  24. }