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

}
相关推荐
迪普阳光开朗很健康7 小时前
UnityScrcpy 可以让你在unity面板里玩手机的插件
unity·游戏引擎
zl_vslam1 天前
SLAM中的非线性优-3D图优化之地平面约束(十四)
算法·计算机视觉·平面·3d
陈言必行1 天前
Unity 之 设备性能分级与游戏画质设置与设备自动适配指南
游戏·unity·游戏引擎
deep_drink1 天前
【论文精读(二十二)】PointMeta:点云江湖的“兵器谱”,用元架构终结算子内卷(CVPR 2023)
深度学习·神经网络·计算机视觉·3d·point cloud
CreasyChan1 天前
Unity DOTS技术栈详解
unity·c#·游戏引擎
塔楼1 天前
VGGT(Visual Geometry Grounded Transformer)解析
深度学习·算法·3d
gshh__1 天前
SuperMap Hi-Fi 3D SDK for Unreal 如何实现横断面分析
3d·ue5·游戏引擎·supermap
学無芷境1 天前
Vesselformer: Towards Complete 3D Vessel Graph Generation from Images
3d
在路上看风景1 天前
1.1 Unity资源生命周期管理与内存机制
unity
CreasyChan1 天前
Unity的ECS(Entity Component System)架构详解
unity·架构·游戏引擎