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

}
相关推荐
WarPigs17 分钟前
Unity设置人物位置无效的原因
unity
程序员正茂32 分钟前
Unity3d行为树Behavior Designer Pro
unity·行为树
郝学胜-神的一滴2 小时前
C++11 工程级应用 10:减少拷贝,让容器跑得更快
服务器·开发语言·c++·游戏引擎·opengl
玖玥拾2 小时前
Lua 基础语法(八) Unity Huatuo (HybridCLR)
开发语言·unity·游戏引擎·lua
平行云2 小时前
国产GPU云渲染适配实战:驱动兼容、编码调优与多路并发
unity·ue5·webrtc·webgl·实时云渲染·云桌面·像素流送
狂人开飞机2 小时前
10、相机系统
游戏引擎·godot
高升说1 天前
手眼 3D 相机选型:先定工作距离,再谈精度,最后定安装
人工智能·数码相机·3d
不吃凉粉1 天前
Unity与AS通信
unity·游戏引擎
利刃大大1 天前
我用 GPT-6 给江南大学建了个 3D 沙盘
gpt·3d·ai·blender·江南大学
不要生病了1 天前
从脑电到彩色三维点云:Neuro-3D 精读与证据边界
3d