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");
    }

}
相关推荐
harrain2 天前
拟合模型与虚幻引擎
游戏引擎·数字孪生·虚幻
Godspeed Zhao2 天前
3D打印的造物革命5
3d
CG_MAGIC2 天前
SketchUp室内布局:户型建模与家具组件高效摆放
3d·贴图·建模教程·渲云渲染
love530love2 天前
ComfyUI-3D-Pack:Windows 下手动编译 mesh_inpaint_processor C++ 加速模块
c++·人工智能·windows·python·3d·hunyuan3d·comfyui-3d-pack
努力长头发的程序猿2 天前
在Unity2d中,根据Y轴决定渲染顺序(URP项目适用)
unity
yeflx2 天前
激光雷达点云处理项目:从零搭建 3D 视觉检测系统
人工智能·3d·视觉检测
出门吃三碗饭2 天前
3DGS如何提升面向仿真的三维高斯重建质量
3d·机器人
DaLiangChen2 天前
Unity 精准 Mesh 点击检测:穿透遮挡 + 单击双击识别
unity·游戏引擎
twe77582582 天前
动态揭示CCP-RIE技术中的缺陷形成:从微观机理到3D动画演示
科技·3d·制造·动画
迪普阳光开朗很健康2 天前
Unity中new() 和实例化有什么区别?
unity·游戏引擎