Unity3D 小案例技巧04------鼠标放置显示(提示)物体名称

使用编辑器Unity2021

1.创建物体------Plane+Cube

 

 2.创建脚本------Love.cs

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Love : MonoBehaviour
{
    bool isShowTip;
    void Start()
    {
        //初始不显示
        isShowTip = false;
    }

    void OnMouseEnter()
    {
        //显示
        isShowTip = true;
    }
    void OnMouseExit()
    {
        //关闭
        isShowTip = false;
    }
    void OnGUI()
    {
        if (isShowTip)
        {
            GUIStyle style = new GUIStyle();
            style.fontSize = 30;
            style.normal.textColor = Color.blue;
            GUI.Label(new Rect(Input.mousePosition.x, Screen.height - Input.mousePosition.y, 100, 100), "白色方块", style);
        }
    }
       
}

3.将脚本添加到Cube组件下

 

 完成!

 

posted @ 2023-03-17 16:07  打工仔-也想飞  阅读(339)  评论(0)    收藏  举报