HitTargetNumberNew.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using DG.Tweening;
  6. /* 击中靶子时显示的分数 */
  7. public class HitTargetNumberNew : MonoBehaviour
  8. {
  9. void Start()
  10. {
  11. DoText();
  12. }
  13. void DoText()
  14. {
  15. RectTransform rtf = this.transform.GetComponentInChildren<Text>().rectTransform;
  16. Sequence seq = DOTween.Sequence();
  17. float scale1 = rtf.localScale.x * 3.3f;
  18. float scale2 = rtf.localScale.x;
  19. rtf.localScale = Vector3.zero;
  20. seq.Append(rtf.DOScale(new Vector3(scale1, scale1, 0), 0.1f));
  21. seq.Append(rtf.DOScale(new Vector3(scale2, scale2, 0), 0.1f));
  22. seq.AppendInterval(1f);
  23. seq.Append(rtf.GetComponent<Text>().DOFade(0, 0.23f));
  24. seq.AppendCallback(delegate () {
  25. Destroy(gameObject);
  26. });
  27. }
  28. public static void Create(float number, int pid)
  29. {
  30. if (number <= 0) return;
  31. string oName = "HitTargetNumber" + pid;
  32. var exist = GameObject.Find(oName);
  33. if (exist && exist.gameObject) {
  34. //Destroy(exist);
  35. exist.SetActive(false);
  36. }
  37. GameObject o = Instantiate(
  38. Resources.Load<GameObject>("Effects/" + oName),
  39. Vector3.zero,
  40. Quaternion.identity,
  41. GameObject.Find("GameCanvas").transform
  42. );
  43. o.name = oName;
  44. o.transform.localPosition = new Vector3(-320, 80, 0);
  45. if (pid == 1) o.transform.localPosition = new Vector3(320, 80, 0);
  46. o.GetComponentInChildren<Text>().text = number.ToString($"f{CommonConfig.ringsPrecision}");
  47. }
  48. }