using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class Tmouse : MonoBehaviour
{
private RectTransform image;
public bool mouse;
void Start()
{
mouse=false;
image = GetComponent<RectTransform>();
}
void Update()
{
mouse = RectTransformUtility.RectangleContainsScreenPoint(image, Input.mousePosition);
Debug.Log("鼠标在图片上");
}
}
将此代码挂载到被检测的UI上,注意我用的UI是RawImage格式的。UI失效即可以不再检测。
20220803_211104