赞
踩
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
-
- public class OnPointerEnterShow3D : MonoBehaviour
- {
- //要显示的ui
- public RectTransform tip;
-
- void Update()
- {
- Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
- RaycastHit hit;
- bool raycast = Physics.Raycast(ray, out hit);
- if (raycast)
- {
- GameObject go = hit.collider.gameObject;
- if (go == this.gameObject)
- {
- tip.gameObject.SetActive(true);
- FollowMouse();
- }
- else
- {
- tip.gameObject.SetActive(false);
- Destory(go);
- }
-
- }
- else
- {
- tip.gameObject.SetActive(false);
- }
-
- }
-
- //ui位置跟随鼠标实时变化
- void FollowMouse()
- {
- tip.position = new Vector3(Input.mousePosition.x, Input.mousePosition.y + 80f, 0f);
- }
-
- }
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.EventSystems;
-
- public class OnPointerEnterShowUI : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
- {
-
- public void OnPointerEnter(PointerEventData eventData)
- {
- Debug.Log("移入");
- transform.GetChild(1).gameObject.SetActive(true);
- }
- public void OnPointerExit(PointerEventData eventData)
- {
- Debug.Log("移出");
- transform.GetChild(1).gameObject.SetActive(false);
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。