ArrowLightSick.cs 924 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. /* 让箭发光(用于标记最新射出的一支箭) */
  5. public class ArrowLightSick : MonoBehaviour
  6. {
  7. [SerializeField] Material[] defaultMats;
  8. [SerializeField] Material lightSickMat;
  9. static HashSet<ArrowLightSick> set = new HashSet<ArrowLightSick>();
  10. void Start()
  11. {
  12. set.Add(this);
  13. }
  14. void OnDestroy()
  15. {
  16. set.Remove(this);
  17. }
  18. public void Hit() {
  19. MeshRenderer mr = this.GetComponent<MeshRenderer>();
  20. Material[] mats = mr.materials;
  21. mats[1] = lightSickMat;
  22. mr.materials = mats;
  23. }
  24. void Recovery() {
  25. MeshRenderer mr = this.GetComponent<MeshRenderer>();
  26. mr.materials = defaultMats;
  27. }
  28. public static void RecoveryAll()
  29. {
  30. foreach (var item in set)
  31. {
  32. item.Recovery();
  33. }
  34. }
  35. }