当前位置: 首页 > article >正文

使用射线单击物体显示,点击物体隐藏

// 检测鼠标左键的点击事件
if (Input.GetMouseButtonUp(0))
{
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); // 创建射线从相机指向鼠标点击位置

            if (Physics.Raycast(ray, out hit)) // 如果射线击中了物体
            {
                GameObject clickedObject = hit.transform.gameObject; // 获取被点击的物体
                if (clickedObject.name == "Left") //第一排左
                {
                    if ((!ModelAir_Animal[1].activeSelf) || (!ModelAir_Animal[0].activeSelf))
                    {
                        //传递给安卓为true
                        AndroidMessage.ins.getUnityCallFunction()?.ElectricalStatusToggle(1, true);
                        Debug.Log("打开Left:" + ModelAir_Animal[1].activeSelf);
                    }
                    if (ModelAir_Animal[1].activeSelf && ModelAir_Animal[0].activeSelf)
                    {
                        //传递给安卓为false
                        AndroidMessage.ins.getUnityCallFunction()?.ElectricalStatusToggle(1, false);
                        Debug.Log("关闭Left:" + ModelAir_Animal[1].activeSelf);
                    }
                }
                if (clickedObject.name == "MiddleLeft") //第一排左中
                {
                    if ((!ModelAir_Animal[2].activeSelf) || (!ModelAir_Animal[0].activeSelf))
                    {
                        //传递给安卓为true
                        AndroidMessage.ins.getUnityCallFunction()?.ElectricalStatusToggle(3, true);
                        Debug.Log("打开MiddleLeft:" + ModelAir_Animal[2].activeSelf);
                    }
                    if (ModelAir_Animal[2].activeSelf && ModelAir_Animal[0].activeSelf)
                    {
                        //传递给安卓为false
                        AndroidMessage.ins.getUnityCallFunction()?.ElectricalStatusToggle(3, false);
                        Debug.Log("关闭MiddleLeft:" + ModelAir_Animal[2].activeSelf);
                    }
                }
                if (clickedObject.name == "MiddleRight") //第一排右中
                {
                    if ((!ModelAir_Animal[4].activeSelf) || (!ModelAir_Animal[0].activeSelf))
                    {
                        //传递给安卓为true
                        AndroidMessage.ins.getUnityCallFunction()?.ElectricalStatusToggle(6, true);
                        Debug.Log("打开MiddleRight:" + ModelAir_Animal[4].activeSelf);
                    }
                    if (ModelAir_Animal[4].activeSelf && ModelAir_Animal[0].activeSelf)
                    {
                        //传递给安卓为false
                        AndroidMessage.ins.getUnityCallFunction()?.ElectricalStatusToggle(6, false);
                        Debug.Log("关闭MiddleRight:" + ModelAir_Animal[4].activeSelf);
                    }
                }
                if (clickedObject.name == "Right") //第一排右
                {
                    if ((!ModelAir_Animal[3].activeSelf) || (!ModelAir_Animal[0].activeSelf))
                    {
                        //传递给安卓为true
                        AndroidMessage.ins.getUnityCallFunction()?.ElectricalStatusToggle(4, true);
                        Debug.Log("打开Right:" + ModelAir_Animal[3].activeSelf);
                    }
                    if (ModelAir_Animal[3].activeSelf && ModelAir_Animal[0].activeSelf)
                    {
                        //传递给安卓为false
                        AndroidMessage.ins.getUnityCallFunction()?.ElectricalStatusToggle(4, false);
                        Debug.Log("关闭Right:" + ModelAir_Animal[3].activeSelf);
                    }
                }
                if (clickedObject.name == "Defrost") //第一排窗
                {
                    if ((!ModelAir_Animal[5].activeSelf) || (!ModelAir_Animal[0].activeSelf))
                    {
                        //传递给安卓为true
                        AndroidMessage.ins.getUnityCallFunction()?.ElectricalStatusToggle(7, true);
                        Debug.Log("打开Defrost:" + ModelAir_Animal[5].activeSelf);
                    }
                    if (ModelAir_Animal[5].activeSelf && ModelAir_Animal[0].activeSelf)
                    {
                        //传递给安卓为false
                        AndroidMessage.ins.getUnityCallFunction()?.ElectricalStatusToggle(7, false);
                        Debug.Log("关闭Defrost:" + ModelAir_Animal[5].activeSelf);
                    }
                }
                if (clickedObject.name == "LeftLeg") //第一排左腿
                {
                    if ((!ModelAir_Animal[6].activeSelf) || (!ModelAir_Animal[0].activeSelf))
                    {
                        //传递给安卓为true
                        AndroidMessage.ins.getUnityCallFunction()?.ElectricalStatusToggle(2, true);
                        Debug.Log("打开LeftLeg:" + ModelAir_Animal[6].activeSelf);
                    }
                    if (ModelAir_Animal[6].activeSelf && ModelAir_Animal[0].activeSelf)
                    {
                        //传递给安卓为false
                        AndroidMessage.ins.getUnityCallFunction()?.ElectricalStatusToggle(2, false);
                        Debug.Log("关闭LeftLeg:" + ModelAir_Animal[6].activeSelf);
                    }
                }
                if (clickedObject.name == "RightLeg") //第一排右腿
                {
                    if ((!ModelAir_Animal[7].activeSelf) || (!ModelAir_Animal[0].activeSelf))
                    {
                        //传递给安卓为true
                        AndroidMessage.ins.getUnityCallFunction()?.ElectricalStatusToggle(5, true);
                        Debug.Log("打开RightLeg:" + ModelAir_Animal[7].activeSelf);
                    }
                    if (ModelAir_Animal[7].activeSelf && ModelAir_Animal[0].activeSelf)
                    {
                        //传递给安卓为false
                        AndroidMessage.ins.getUnityCallFunction()?.ElectricalStatusToggle(5, false);
                        Debug.Log("关闭RightLeg:" + ModelAir_Animal[7].activeSelf);
                    }
                }
                if (clickedObject.name == "SecondLeft") //第二排左
                {
                    if ((!ModelAir_Animal[8].activeSelf) || (!ModelAir_Animal[12].activeSelf))
                    {
                        //传递给安卓为true
                        AndroidMessage.ins.getUnityCallFunction()?.ElectricalStatusToggle(16, true);
                        Debug.Log("打开SecondLeft:" + ModelAir_Animal[8].activeSelf);
                    }
                    if (ModelAir_Animal[8].activeSelf && ModelAir_Animal[12].activeSelf)
                    {
                        //传递给安卓为false
                        AndroidMessage.ins.getUnityCallFunction()?.ElectricalStatusToggle(16, false);
                        Debug.Log("关闭SecondLeft:" + ModelAir_Animal[8].activeSelf);
                    }
                }
                if (clickedObject.name == "SecondRight") //第二排右
                {
                    if ((!ModelAir_Animal[9].activeSelf) || (!ModelAir_Animal[12].activeSelf))
                    {
                        //传递给安卓为true
                        AndroidMessage.ins.getUnityCallFunction()?.ElectricalStatusToggle(64, true);
                        Debug.Log("打开SecondRight:" + ModelAir_Animal[9].activeSelf);
                    }
                    if (ModelAir_Animal[9].activeSelf && ModelAir_Animal[12].activeSelf)
                    {
                        //传递给安卓为false
                        AndroidMessage.ins.getUnityCallFunction()?.ElectricalStatusToggle(64, false);
                        Debug.Log("关闭SecondRight:" + ModelAir_Animal[9].activeSelf);
                    }
                }
                if (clickedObject.name == "SecondLeftLeg") //第二排左腿
                {
                    if ((!ModelAir_Animal[10].activeSelf) || (!ModelAir_Animal[12].activeSelf))
                    {
                        //传递给安卓为true
                        AndroidMessage.ins.getUnityCallFunction()?.ElectricalStatusToggle(17, true);
                        Debug.Log("打开SecondLeftLeg:" + ModelAir_Animal[10].activeSelf);
                    }
                    if (ModelAir_Animal[10].activeSelf && ModelAir_Animal[12].activeSelf)
                    {
                        //传递给安卓为false
                        AndroidMessage.ins.getUnityCallFunction()?.ElectricalStatusToggle(17, false);
                        Debug.Log("关闭SecondLeftLeg:" + ModelAir_Animal[10].activeSelf);
                    }
                }
                if (clickedObject.name == "SecondRightLeg") //第二排右腿
                {
                    if ((!ModelAir_Animal[11].activeSelf) || (!ModelAir_Animal[12].activeSelf))
                    {
                        //传递给安卓为true
                        AndroidMessage.ins.getUnityCallFunction()?.ElectricalStatusToggle(65, true);
                        Debug.Log("打开SecondRightLeg:" + ModelAir_Animal[11].activeSelf);
                    }
                    if (ModelAir_Animal[11].activeSelf && ModelAir_Animal[12].activeSelf)
                    {
                        //传递给安卓为false
                        AndroidMessage.ins.getUnityCallFunction()?.ElectricalStatusToggle(65, false);
                        Debug.Log("关闭SecondRightLeg:" + ModelAir_Animal[11].activeSelf);
                    }
                }
            }

http://www.kler.cn/news/156619.html

相关文章:

  • LD_PRELOAD劫持、ngixn临时文件、无需临时文件rce
  • 人机交互——言语信息表示模型
  • NetApp EF 系列全闪存存储,为实时分析、HPC 和数据库等性能敏感型工作负载提供助力
  • 数字孪生3D场景开发工具:弥补不足,开拓全新可能
  • Linux入门攻坚——7、磁盘管理——文件系统挂载管理及RAID、LVM
  • 学生犯错误老师应该怎么教育
  • colab notebook导出为PDF
  • C语言图书管理系统的代码,包括图书录入、查询、插入、修改和删除功能。
  • 奇迹mu 架设过程中可能会出现的问题及解决办法
  • 微机原理——定时器8253(8254)学习1
  • ROS第一个程序——helloworld
  • error转string
  • Linux 基础知识整理(一)
  • GEE:Sobel算子卷积
  • 第三届首都高校“青春智慧”新铁人三项公开赛圆满落幕
  • .NET8 依赖注入
  • docker搭建nginx实现负载均衡
  • Vue 或者 React 中,什么情况下会用 Es6 的 Class 类
  • 计算机基础知识63
  • AC自动机
  • 2024版软件测试面试100问(答案+文档)
  • 【苍穹外卖】——第一天
  • Docker快速入门(docker加速,镜像,容器,数据卷常见命令操作整理)
  • 基于YOLOv8深度学习的PCB板缺陷检测系统【python源码+Pyqt5界面+数据集+训练代码】目标检测
  • 如何进行卷积特征可视化
  • 解锁网络速度的利器:CDN加速技术探析
  • Docker 安装部署 Sentinel Dashboard
  • 内存是如何工作的
  • (5h)Unity3D快速入门之Roll-A-Ball游戏开发
  • Python——import和from import方法总结