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

}
相关推荐
元气少女小圆丶2 小时前
unity发布web嵌入到前端页面的接受参数
前端·unity·webgl
HH‘HH3 小时前
Unity 打包程序设置及注意事项全攻略
unity·游戏引擎
fqbqrr6 小时前
2607d,parin游戏引擎
游戏引擎·d
qq_170264757 小时前
unity里 Burst的用法
unity·游戏引擎
苏州邦恩精密8 小时前
蔡司3D扫描仪采购要点及厂家服务能力分析
人工智能·科技·3d·自动化·汽车
small-pudding10 小时前
3D 麻将贴图开启 Mipmaps 后远处边缘发黑,关闭后又发白,为什么?
3d·贴图
云空10 小时前
《Three.js 完整版3D魔方:带贴纸+中心固定+自动求解复原》
前端·javascript·3d·three.js
HH‘HH10 小时前
Unity 相机与光照调整:从基础到进阶的实战指南
unity
云空11 小时前
《Three.js 可操控3D魔方(键盘转动+打乱+复原)》
javascript·学习·游戏·3d·three.js
HH‘HH1 天前
Unity引擎界面各个功能面板详细介绍
unity·游戏引擎