ArrowLightSick.cs 864 B

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