1. 程式人生 > >U3D顯示滑鼠懸停位置物件的名字

U3D顯示滑鼠懸停位置物件的名字

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

public class MouseClickBehaviourScript : MonoBehaviour {
    bool isShowTip;
    // Use this for initialization
    void Start () {
        isShowTip = false;
	}
	
	// Update is called once per frame
	void Update () {
		
	}

    void OnMouseEnter()
    {
        isShowTip = true;
    }

    void OnMouseExit()
    {
        isShowTip = false;
    }

    void OnGUI()
    {
        if (isShowTip)
        {
            GUI.Label(new Rect(Input.mousePosition.x, Screen.height - Input.mousePosition.y, 100, 40), "My name is " + name);
        }
    }
}