参考链接
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
public class Text_input : MonoBehaviour,IPointerDownHandler
{
public CanvasGroup canvasGroup;
public InputField inputField;
public void OnPointerDown(PointerEventData eventData)
{
if (eventData.button == PointerEventData.InputButton.Left)
{
canvasGroup.blocksRaycasts = true;
canvasGroup.interactable = true;
}
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.KeypadEnter)|| Input.GetKeyDown(KeyCode.Return))
{
canvasGroup.blocksRaycasts = false;
canvasGroup.interactable = false;
}
if (Input.GetMouseButtonDown(1))
{
canvasGroup.blocksRaycasts = false;
canvasGroup.interactable = false;
}
}
}