DNP_CubeHighlight.cs 863 B

1234567891011121314151617181920212223242526272829303132333435
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace DamageNumbersPro.Demo
  5. {
  6. public class DNP_CubeHighlight : MonoBehaviour
  7. {
  8. public string propertyName = "_Color";
  9. public AnimationCurve propertyCurve;
  10. public float destructionDelay = 0.2f;
  11. Material mat;
  12. int propertyID;
  13. float startTime;
  14. void Start()
  15. {
  16. startTime = Time.time;
  17. propertyID = Shader.PropertyToID(propertyName);
  18. MeshRenderer mr = GetComponent<MeshRenderer>();
  19. mat = mr.material;
  20. Destroy(gameObject, destructionDelay);
  21. }
  22. void FixedUpdate()
  23. {
  24. mat.SetColor(propertyID, new Color(1, 0, 0, propertyCurve.Evaluate(Time.time - startTime)));
  25. }
  26. }
  27. }