需要将技能图标对应的位置Pos赋给Tips即可。下面是计算 Pos 的核心代码:
using UnityEngine; public class LgsTest : MonoBehaviour { [SerializeField] GameObject skillIcon; GameObject TipsInfo; //到实际的项目中,只需要将改对象即可 Vector3 offVec3 = Vector3.zero; //偏移量 public static Camera m_Camera; void Start() { if (null == m_Camera) m_Camera = UICamera.FindCameraForLayer(skillIcon.layer).GetComponent<Camera>(); UIEventListener.Get(skillIcon).onPress = OnPressSkillIconBtn; } void OnPressSkillIconBtn(GameObject go, bool show) { if (null == m_Camera) m_Camera = UICamera.FindCameraForLayer(skillIcon.layer).GetComponent<Camera>(); if (show) { Vector3 screenPos = m_Camera.WorldToScreenPoint(skillIcon.transform.position); Vector3 finPos = m_Camera.ScreenToWorldPoint(screenPos + offVec3); TipsInfo.transform.position = finPos; TipsInfo.SetActive(true); } else { TipsInfo.SetActive(false); } } }