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

}
相关推荐
jiayong231 天前
虚拟仿真大屏系统——完整实施手册
3d·虚拟现实
mxwin1 天前
unity shader中 ddx ddy是什么
unity·游戏引擎·shader
郝学胜-神的一滴1 天前
[简化版 GAMES 101] 计算机图形学 08:三角形光栅化上
c++·unity·游戏引擎·godot·图形渲染·opengl·unreal
nnsix1 天前
Unity ILRuntime 笔记
unity·游戏引擎
阿斯加德D1 天前
天国:拯救 2风灵月影修改器下载(已汉化)2026最新版下载分享
测试工具·游戏·3d·游戏程序
nnsix1 天前
Unity API 兼容的 .NET Standard 2.1 和 .NET Framework 区别
unity·游戏引擎·.net
mxwin1 天前
Unity Shader 制作半透明物体 使用多Pass提前写入深度的方式 避免穿模
unity·游戏引擎
nnsix1 天前
Unity HybridCLR 笔记
笔记·unity·游戏引擎
Hi202402171 天前
Apollo CUDA-BEVFusion 高性能 3D 目标检测
人工智能·目标检测·3d
AZaLEan__2 天前
CSS3:从 2D 变换到 3D 翻转
前端·3d·css3