1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- namespace Spine.Unity.Examples {
- public class MaterialPropertyBlockExample : MonoBehaviour {
- public float timeInterval = 1f;
- public Gradient randomColors = new Gradient();
- public string colorPropertyName = "_FillColor";
- MaterialPropertyBlock mpb;
- float timeToNextColor = 0;
- void Start () {
- mpb = new MaterialPropertyBlock();
- }
- void Update () {
- if (timeToNextColor <= 0) {
- timeToNextColor = timeInterval;
- Color newColor = randomColors.Evaluate(UnityEngine.Random.value);
- mpb.SetColor(colorPropertyName, newColor);
- GetComponent<MeshRenderer>().SetPropertyBlock(mpb);
- }
- timeToNextColor -= Time.deltaTime;
- }
- }
- }
|