1. 在场景中添加事件系统
2. 为主相机添加射线检测
3. 为物体挂载以下脚本,物体必须带碰撞体
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;// 挂在物体上,需要添加碰撞体
public class DoorAction : MonoBehaviour, IPointerDownHandler
{// Start is called before the first frame updatevoid Start(){}// Update is called once per framevoid Update(){}public void OnPointerClick(PointerEventData eventData){//你要触发的代码print("xxx");}//当检测到鼠标在该物体上有“按下”操作时,触发以下函数public void OnPointerDown(PointerEventData eventData){//你要触发的代码print("xxx");}}