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

}
相关推荐
一线灵3 小时前
跨平台游戏引擎 Axmol-2.10.0 发布
游戏引擎
棒棒的皮皮11 小时前
【Python】Open3d用于3D测高项目
python·3d·open3d
沉默金鱼12 小时前
Unity实用技能-格式化format文字
ui·unity·游戏引擎
jyy_9912 小时前
通过网页地址打开unity的exe程序,并传参
unity
qq_205279051 天前
Unity TileMap 使用经验
unity·游戏引擎
心灵宝贝1 天前
Mac Unity 2018.dmg游戏工具 安装步骤 简单易懂教程(附安装包)
macos·unity·游戏引擎
TO_ZRG1 天前
Unity SDK 通过 Registry 分发及第三方依赖处理指南
unity·游戏引擎
7***n751 天前
C++在游戏中的Cocos2d-x
游戏·游戏引擎·cocos2d
CV实验室1 天前
CV论文速递:覆盖视频生成与理解、3D视觉与运动迁移、多模态与跨模态智能、专用场景视觉技术等方向 (11.17-11.21)
人工智能·计算机视觉·3d·论文·音视频·视频生成
龙智DevSecOps解决方案2 天前
Perforce《2025游戏技术现状报告》Part 1:游戏引擎技术的广泛影响以及生成式AI的成熟之路
人工智能·unity·游戏引擎·游戏开发·perforce