DNP_Crosshair.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. namespace DamageNumbersPro.Demo
  6. {
  7. public class DNP_Crosshair : MonoBehaviour
  8. {
  9. public static DNP_Crosshair instance;
  10. public static bool targetEnemy;
  11. public Color defaultColor = new Color(1, 1, 1, 0.6f);
  12. public float defaultScale = 1f;
  13. public Color enemyColor = new Color(1, 0.2f, 0.2f, 0.8f);
  14. public float enemyScale = 1.15f;
  15. Image image;
  16. void Awake()
  17. {
  18. instance = this;
  19. image = GetComponent<Image>();
  20. }
  21. void FixedUpdate()
  22. {
  23. if(Cursor.visible)
  24. {
  25. image.color = Color.Lerp(image.color, new Color(1,1,1,0), Time.fixedDeltaTime * 7f);
  26. }
  27. else if(targetEnemy)
  28. {
  29. image.color = Color.Lerp(image.color, enemyColor, Time.fixedDeltaTime * 7f);
  30. float scale = Mathf.Lerp(transform.localScale.x, enemyScale, Time.fixedDeltaTime * 7f);
  31. transform.localScale = new Vector3(scale, scale, 1);
  32. }
  33. else
  34. {
  35. image.color = Color.Lerp(image.color, defaultColor, Time.fixedDeltaTime * 7f);
  36. float scale = Mathf.Lerp(transform.localScale.x, defaultScale, Time.fixedDeltaTime * 7f);
  37. transform.localScale = new Vector3(scale, scale, 1);
  38. }
  39. }
  40. public void HitTarget()
  41. {
  42. transform.localScale = new Vector3(1.7f, 1.7f, 1f);
  43. image.color = Color.red;
  44. }
  45. public void HitWall()
  46. {
  47. transform.localScale = new Vector3(1.5f, 1.5f, 1f);
  48. image.color = Color.white;
  49. }
  50. }
  51. }