Vector3 screen= Camera.main.WorldToScreenPoint(transform.position+Vector3.up*0.2f); GameObject gameObject = GameObject.Instantiate(damageText); TMP_Text text = gameObject.GetComponentInChildren<TMP_Text>(); text.text = "-" + ((int)damage).ToString(); //Destroy(gameObject, 1f); Transform textTrans = gameObject.transform.GetChild(0); screen.z = 0; textTrans.position = screen; Vector3 dir = collision.transform.position - transform.position; dir.Normalize(); float d= Vector3.Dot(collision.transform.parent.right,dir); Vector3 temp = new Vector3(-d*Screen.width*0.5f,Random.Range(0.5f, 1f)*Screen.height*0.5f,0); (textTrans as RectTransform).DOLocalMove(temp, 0.8f).SetEase(Ease.OutBack); text.DOFade(0, 0.5f).SetEase(Ease.OutCirc).SetDelay(0.3f); textTrans.DOScale(1.5f,0.8f).SetEase(Ease.OutCirc);
弹字方向为怪物在角色的相对方向。
原文:https://www.cnblogs.com/DazeJiang/p/14381379.html