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组件下

完成!


浙公网安备 33010602011771号