UGUI在創建時,會自動在【Hierarchy】下產生『Canvas』和『EventSystem』兩個物件,『EventSystem』便是用來處理點擊等事件的存在,所以會使用它來得知是否有滑鼠點擊任何UGUI物件,並可取得所點擊的介面物件。
- using UnityEngine;
- using System.Collections;
- using UnityEngine.EventSystems;
- public class MainProcess : MonoBehaviour {
- void Update ()
- {
- if( Input.GetMouseButtonDown( 0 ) )
- {
- if( EventSystem.current.IsPointerOverGameObject() )
- {
- Debug.Log( "有介面被點擊到!" );
- Debug.Log( EventSystem.current.currentSelectedGameObject );
- }
- }
- }
- }
沒有留言:
張貼留言