| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.EventSystems;
- public class RecordThePoints : MonoBehaviour, IPointerClickHandler
- {
- public RectTransform rectTransform;
- public int secor;
- public void OnPointerClick(PointerEventData eventData)
- {
- Debug.Log("鼠标点击了");
- // 获取点击位置相对于所在UI元素的坐标
- Vector2 localPoint;
- if (RectTransformUtility.ScreenPointToLocalPointInRectangle(GetComponent<RectTransform>(),eventData.position,
- null,
- out localPoint))
- {
- Debug.Log(localPoint);
- //计算得分
- if (localPoint.y >= -22f && localPoint.y <= 22f && localPoint.x >= -22f && localPoint.x <= 22f)
- {
- Debug.Log("得10分");
- GeneratingTarget.gm.score += 10;
- GeneratingTarget.gm.ShowScore();
- GeneratingTarget.gm.hitCount++;
- }
- else if (localPoint.y >= -44f && localPoint.y <= 44f && localPoint.x >= -44f && localPoint.x <= 44f)
- {
- Debug.Log("得9分");
- GeneratingTarget.gm.score += 9;
- GeneratingTarget.gm.ShowScore();
- GeneratingTarget.gm.hitCount++;
- }
- else if (localPoint.y >= -66f && localPoint.y <= 66f && localPoint.x >= -66f && localPoint.x <= 66f)
- {
- Debug.Log("得8分");
- GeneratingTarget.gm.score += 8;
- GeneratingTarget.gm.ShowScore();
- GeneratingTarget.gm.hitCount++;
- }
- else if (localPoint.y >= -88f && localPoint.y <= 88f && localPoint.x >= -88f && localPoint.x <= 88f)
- {
- Debug.Log("得7分");
- GeneratingTarget.gm.score += 7;
- GeneratingTarget.gm.ShowScore();
- GeneratingTarget.gm.hitCount++;
- }
- else if (localPoint.y >= -110f && localPoint.y <= 110f && localPoint.x >= -110f && localPoint.x <= 110f)
- {
- Debug.Log("得6分");
- GeneratingTarget.gm.score += 6;
- GeneratingTarget.gm.ShowScore();
- GeneratingTarget.gm.hitCount++;
- }
- else if (localPoint.y >= -130f && localPoint.y <= 130f && localPoint.x >= -130f && localPoint.x <= 130f)
- {
- Debug.Log("得5分");
- GeneratingTarget.gm.score += 5;
- GeneratingTarget.gm.ShowScore();
- GeneratingTarget.gm.hitCount++;
- }
- else if (localPoint.y >= -150f && localPoint.y <= 150f && localPoint.x >= -150f && localPoint.x <= 150f)
- {
- Debug.Log("得4分");
- GeneratingTarget.gm.score += 4;
- GeneratingTarget.gm.ShowScore();
- GeneratingTarget.gm.hitCount++;
- }
- else if (localPoint.y >= -170f && localPoint.y <= 170f && localPoint.x >= -170f && localPoint.x <= 170f)
- {
- Debug.Log("得3分");
- GeneratingTarget.gm.score += 3;
- GeneratingTarget.gm.ShowScore();
- GeneratingTarget.gm.hitCount++;
- }
- else if (localPoint.y >= -190f && localPoint.y <= 190f && localPoint.x >= -190f && localPoint.x <= 190f)
- {
- Debug.Log("得2分");
- GeneratingTarget.gm.score += 2;
- GeneratingTarget.gm.ShowScore();
- GeneratingTarget.gm.hitCount++;
- }
- else if (localPoint.y >= -210f && localPoint.y <= 210f && localPoint.x >= -210f && localPoint.x <= 210f)
- {
- GeneratingTarget.gm.score += 1;
- GeneratingTarget.gm.ShowScore();
- GeneratingTarget.gm.hitCount++;
- Debug.Log("得1分");
- }
- }
- }
- public void ystemStopped()
- {
- Debug.Log("返回分数" + secor);
- }
- public void OnTriggerEnter2D(Collider2D collision)
- {
- float width = rectTransform.sizeDelta.x;
- float height = rectTransform.sizeDelta.y;
- float radius = 0.5f * Mathf.Sqrt(width * width + height * height);
- Debug.Log(radius);
- }
- }
|