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 小时前
Unity 材质预览才弹 d3dcompiler_47.dll?先分清编辑器 SDK、着色器缓存和玩家包
程序人生·3d·unity·电脑·材质
xcLeigh4 小时前
Unity基础:使用Transform控制物体缩放——localScale与lossyScale的区别
unity·游戏引擎·教程
郝学胜-神的一滴7 小时前
游戏引擎原理与实践 01:聊聊游戏引擎的前世今生
开发语言·c++·游戏引擎·产品运营·软件工程·产品经理·untiy
淡海水9 小时前
00-Unity和C#的GC剖析与对比-全篇导览
unity·c#·游戏引擎·gc
Zldaisy3d9 小时前
从英特尔Connection苏州大会揭示算力狂飙下的散热范式革命,洞悉增材制造潜力重塑液冷散热版图
3d·制造
字节暗面1 天前
Unity AssetBundle 热更新资源保护排查笔记
unity·游戏加固·资源加密
魔士于安6 天前
unity 丑陋哥布林 哥布林有humannoid 动画没 带动画
unity·游戏引擎·材质·贴图·模型
Zldaisy3d7 天前
中南大学 | 热稳定纳米析出相助力增材制造Al-Fe-Cr-Sc-Zr合金400℃长期热暴露后室温强度保持
3d·制造
陆康永7 天前
3d swipe 拖动 -改为linear css
3d·swiper
小贺儿开发7 天前
Unity 家居视频遥控(细节优化)
科技·unity·程序员·udp·视频·工具·通信