需求:鼠标移动到3d模型上,显示其描述信息。
做法:创建一个Text,当鼠标移到某一个模型上时,跟随模型位置,显示描述信息;鼠标移出时,Text为空。
public GameObject mModel;
public GameObject mText;
private void OnMouseEnter()
{
Vector3 _objScreenPos = Camera.main.WorldToScreenPoint(mModel.transform.position);
mText.Getcomponent<RectTransform>().position = new Vectors(_objScreenPos.x,_objScreenPos.y,0);
mText.Getcomponent<Text>().text = "获取的描述信息";
}
private void OnMouseExit()
{
mText.Getcomponent<Text>().text = "";
}