unity 点击3D物体

  1. 在场景中添加事件系统

2. 为主相机添加射线检测

  1. 为物体挂载以下脚本,物体必须带碰撞体
cs 复制代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;


// 挂在物体上,需要添加碰撞体
public class DoorAction :  MonoBehaviour, IPointerDownHandler
{
    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        
    }

     public void OnPointerClick(PointerEventData eventData)
    {
    	//你要触发的代码
        print("xxx");
    }
    
	//当检测到鼠标在该物体上有"按下"操作时,触发以下函数
    public void OnPointerDown(PointerEventData eventData)
    {
    	//你要触发的代码
         print("xxx");
    }

}
相关推荐
weixin_4419400112 分钟前
【Unity教程】使用vuforia创建简单的AR实例
unity·游戏引擎·ar
郝学胜-神的一滴15 分钟前
[简化版 GAMES 101] 计算机图形学 12:可见性与 Z‑Buffer 深度缓存
unity·godot·图形渲染·three.js·opengl·unreal
归真仙人10 小时前
【UE】LineTraceByProfile
ue5·游戏引擎·ue4·unreal engine
游乐码19 小时前
Unity基础(十一 )资源同步加载
unity·游戏引擎
LONGZETECH19 小时前
汽车仿真教学软件技术实现深度解析:从三维建模到学情数据闭环
c语言·3d·unity·架构·汽车
jinxindeep20 小时前
CVPR26最佳论文提名:SAM3D,单图生成可组合3D场景的基础模型
3d
游乐码21 小时前
unity基础(九)协程原理
unity·游戏引擎
无负今日_tq21 小时前
ESP32-S3 桌面语音移动机器人 DIY:可移动、可对话、带 OLED/RGB 和 3D 打印外壳
3d
毕安格 - BimAngle1 天前
地理配准高级教程:局部坐标(无地理信息)模型篇
3d·cesium·gltf·glb·3d tiles
winlife_1 天前
全程用 AI 做一款商业级手游 · EP0 立项:能做到吗、怎么做、边界在哪
人工智能·unity·ai编程·游戏开发·商业化·mcp·funplay