Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private GraphicRaycaster raycaster;
- private PointerEventData pointerEventData;
- private EventSystem eventSystem;
- // Obtener referencias a los componentes necesarios.
- raycaster = GetComponent<GraphicRaycaster>();
- eventSystem = GetComponent<EventSystem>();
- private void Update()
- {
- // Verificar si se ha hecho clic en el mouse.
- if (Input.GetMouseButtonDown(0))
- {
- // Crear datos de evento de puntero para el raycast.
- pointerEventData = new PointerEventData(eventSystem);
- pointerEventData.position = Input.mousePosition;
- // Crear una lista para almacenar los resultados del raycast.
- var results = new List<RaycastResult>();
- // Realizar el raycast en el Canvas.
- raycaster.Raycast(pointerEventData, results);
- // Procesar los resultados del raycast.
- foreach (var result in results)
- {
- // Verificar si se ha interactuado con un objeto UI (por ejemplo, una Image).
- if (result.gameObject.GetComponent<Image>() != null)
- {
- Debug.Log("Se interactuó con un objeto UI: " + result.gameObject.name);
- item.GetComponent<Image>().sprite = result.gameObject.GetComponent<Image>().sprite;
- // Realiza acciones específicas en respuesta al raycast interactivo.
- // Puedes acceder al objeto UI resultante, como result.gameObject, para realizar acciones específicas.
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement