using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using DG.Tweening; /* 击中靶子时显示的分数 */ public class HitTargetNumberNew : MonoBehaviour { void Start() { DoText(); } void DoText() { RectTransform rtf = this.transform.GetComponentInChildren().rectTransform; Sequence seq = DOTween.Sequence(); float scale1 = rtf.localScale.x * 3.3f; float scale2 = rtf.localScale.x; rtf.localScale = Vector3.zero; seq.Append(rtf.DOScale(new Vector3(scale1, scale1, 0), 0.1f)); seq.Append(rtf.DOScale(new Vector3(scale2, scale2, 0), 0.1f)); seq.AppendInterval(1f); seq.Append(rtf.GetComponent().DOFade(0, 0.23f)); seq.AppendCallback(delegate () { Destroy(gameObject); }); } public static void Create(float number, int pid) { if (number <= 0) return; string oName = "HitTargetNumber" + pid; var exist = GameObject.Find(oName); if (exist && exist.gameObject) { //Destroy(exist); exist.SetActive(false); } GameObject o = Instantiate( Resources.Load("Effects/" + oName), Vector3.zero, Quaternion.identity, GameObject.Find("GameCanvas").transform ); o.name = oName; o.transform.localPosition = new Vector3(-320, 80, 0); if (pid == 1) o.transform.localPosition = new Vector3(320, 80, 0); o.GetComponentInChildren().text = number.ToString($"f{CommonConfig.ringsPrecision}"); } }