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

}
相关推荐
敢敢のwings10 小时前
世界模型与FlashWorld:从“在梦中学习“到秒级3D场景生成
android·学习·3d
Madokaly13 小时前
基类 DG.Tweening.Tween的源码解读
unity
Behaviour14 小时前
Unity游戏之Jenkins的安装部署应用
游戏·unity·jenkins
大Mod_abfun15 小时前
Unity案例10-水晶矿石碰撞碎裂案例
unity·游戏引擎
xcLeigh17 小时前
Unity基础:Input输入系统入门——键盘、鼠标与触摸检测
unity·计算机外设·游戏引擎
雾沉川1 天前
d3dx9_43.dll 丢失报错原因分析及三种标准修复方法
microsoft·3d
zhchyun20081 天前
【Unity UI 进阶】仿 Element UI 打造企业级 Unity UI 组件库(05)
ui·unity·游戏引擎
蓝速科技2 天前
蓝速科技圆柱形 3D 全息舱全天候值守实战指南
科技·3d
2601_966871402 天前
AE影视后期特效-遮罩/调色/抠像/MG动画/3D/Vlog制作
3d