天天看點

unity--滑鼠放上顯示物體資訊和物體高光效果

unity--滑鼠放上顯示物體資訊和物體高光效果

滑鼠放在物體上顯示資訊代碼

using UnityEngine;
using System.Collections;

public class info : MonoBehaviour {

    bool isShowInfo;
    public GUIStyle _GUIStyle;
    public float Offset = 15;
    public string Info = "名字";
	// Use this for initialization
	void Start () {
        isShowInfo = false;
	
	}
    void OnMouseEnter() 
    {
        isShowInfo = true;
       // print("onmouseenter");
    }
    void OnMouseExit() 
    {
        isShowInfo = false;
       // print("onmouseexit");
    }
	
	// Update is called once per frame
	void Update () {
	
	}
    void OnGUI() 
    {
        
        
        if (isShowInfo)
        {
            print("123");
            GUI.Label(new Rect(Input.mousePosition.x + Offset, Screen.height - Input.mousePosition.y, 100, 100), Info, _GUIStyle);
        }
    }
}
           

物體高光效果使用的插件實作HighlightingSystem

unity--滑鼠放上顯示物體資訊和物體高光效果
unity--滑鼠放上顯示物體資訊和物體高光效果

demo案例