RecordThePoints.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.EventSystems;
  5. public class RecordThePoints : MonoBehaviour, IPointerClickHandler
  6. {
  7. public RectTransform rectTransform;
  8. public int secor;
  9. public void OnPointerClick(PointerEventData eventData)
  10. {
  11. Debug.Log("鼠标点击了");
  12. // 获取点击位置相对于所在UI元素的坐标
  13. Vector2 localPoint;
  14. if (RectTransformUtility.ScreenPointToLocalPointInRectangle(GetComponent<RectTransform>(),eventData.position,
  15. null,
  16. out localPoint))
  17. {
  18. Debug.Log(localPoint);
  19. //计算得分
  20. if (localPoint.y >= -22f && localPoint.y <= 22f && localPoint.x >= -22f && localPoint.x <= 22f)
  21. {
  22. Debug.Log("得10分");
  23. GeneratingTarget.gm.score += 10;
  24. GeneratingTarget.gm.ShowScore();
  25. GeneratingTarget.gm.hitCount++;
  26. }
  27. else if (localPoint.y >= -44f && localPoint.y <= 44f && localPoint.x >= -44f && localPoint.x <= 44f)
  28. {
  29. Debug.Log("得9分");
  30. GeneratingTarget.gm.score += 9;
  31. GeneratingTarget.gm.ShowScore();
  32. GeneratingTarget.gm.hitCount++;
  33. }
  34. else if (localPoint.y >= -66f && localPoint.y <= 66f && localPoint.x >= -66f && localPoint.x <= 66f)
  35. {
  36. Debug.Log("得8分");
  37. GeneratingTarget.gm.score += 8;
  38. GeneratingTarget.gm.ShowScore();
  39. GeneratingTarget.gm.hitCount++;
  40. }
  41. else if (localPoint.y >= -88f && localPoint.y <= 88f && localPoint.x >= -88f && localPoint.x <= 88f)
  42. {
  43. Debug.Log("得7分");
  44. GeneratingTarget.gm.score += 7;
  45. GeneratingTarget.gm.ShowScore();
  46. GeneratingTarget.gm.hitCount++;
  47. }
  48. else if (localPoint.y >= -110f && localPoint.y <= 110f && localPoint.x >= -110f && localPoint.x <= 110f)
  49. {
  50. Debug.Log("得6分");
  51. GeneratingTarget.gm.score += 6;
  52. GeneratingTarget.gm.ShowScore();
  53. GeneratingTarget.gm.hitCount++;
  54. }
  55. else if (localPoint.y >= -130f && localPoint.y <= 130f && localPoint.x >= -130f && localPoint.x <= 130f)
  56. {
  57. Debug.Log("得5分");
  58. GeneratingTarget.gm.score += 5;
  59. GeneratingTarget.gm.ShowScore();
  60. GeneratingTarget.gm.hitCount++;
  61. }
  62. else if (localPoint.y >= -150f && localPoint.y <= 150f && localPoint.x >= -150f && localPoint.x <= 150f)
  63. {
  64. Debug.Log("得4分");
  65. GeneratingTarget.gm.score += 4;
  66. GeneratingTarget.gm.ShowScore();
  67. GeneratingTarget.gm.hitCount++;
  68. }
  69. else if (localPoint.y >= -170f && localPoint.y <= 170f && localPoint.x >= -170f && localPoint.x <= 170f)
  70. {
  71. Debug.Log("得3分");
  72. GeneratingTarget.gm.score += 3;
  73. GeneratingTarget.gm.ShowScore();
  74. GeneratingTarget.gm.hitCount++;
  75. }
  76. else if (localPoint.y >= -190f && localPoint.y <= 190f && localPoint.x >= -190f && localPoint.x <= 190f)
  77. {
  78. Debug.Log("得2分");
  79. GeneratingTarget.gm.score += 2;
  80. GeneratingTarget.gm.ShowScore();
  81. GeneratingTarget.gm.hitCount++;
  82. }
  83. else if (localPoint.y >= -210f && localPoint.y <= 210f && localPoint.x >= -210f && localPoint.x <= 210f)
  84. {
  85. GeneratingTarget.gm.score += 1;
  86. GeneratingTarget.gm.ShowScore();
  87. GeneratingTarget.gm.hitCount++;
  88. Debug.Log("得1分");
  89. }
  90. }
  91. }
  92. public void ystemStopped()
  93. {
  94. Debug.Log("返回分数" + secor);
  95. }
  96. public void OnTriggerEnter2D(Collider2D collision)
  97. {
  98. float width = rectTransform.sizeDelta.x;
  99. float height = rectTransform.sizeDelta.y;
  100. float radius = 0.5f * Mathf.Sqrt(width * width + height * height);
  101. Debug.Log(radius);
  102. }
  103. }