public class someclass:monobehaviour
{
public EventSystem eventssystem;
public GraphicRaycaster gra;
/// <summary>
/// 射线检测
/// </summary>
/// <param name="Name"></param>
/// <returns></returns>
public bool MouseOver(string Name)
{
var mPointerEventData = new PointerEventData(eventssystem);
mPointerEventData.position = Input.mousePosition;
List<RaycastResult> results = new List<RaycastResult>();
gra.Raycast(mPointerEventData, results);
return results.Any(data => data.gameObject.name == Name);
}
}
private void Update()
{
if (Input.GetMouseButtonDown(0))
{
Vector3 point = Camera.main.ScreenToWorldPoint(Input.mousePosition);
point.z = transform.position.z;
if (sprite.bounds.Contains(point))
{
ctrl.fsm.PerformTransition(Transition.PieceClick);
}
}
}