南阳网站建站培训深圳画册设计网站

张小明 2026/1/9 13:41:49
南阳网站建站培训,深圳画册设计网站,淘宝服务商平台,东莞网站建设外贸视频教程#xff1a; https://www.bilibili.com/video/BV11D5QzgEpw?spm_id_from333.788.videopod.sectionsvd_source25b783f5f945c4507229e9dec657b5bb 1. 场景搭建 创建工程文件素材导入将游戏场景预制体实例化设置场景光颜色为#xff08;29, 26, 00#xff09;…视频教程https://www.bilibili.com/video/BV11D5QzgEpw?spm_id_from333.788.videopod.sectionsvd_source25b783f5f945c4507229e9dec657b5bb1. 场景搭建创建工程文件素材导入将游戏场景预制体实例化设置场景光颜色为29, 26, 00设置天空颜色为128, 110, 36设置 camera 位置为-31, 25, -20设置 camera 旋转角度为37, 53, 6设置 camera 为正交视野Size 为 8正交投影常用于 2D 游戏开发、UI 设计、建筑图纸绘制等这些场景更关注物体实际尺寸和相对位置不需要模拟真实 3D 空间深度感。比如 2D 横版过关游戏正交投影能保证角色和场景元素大小一致便于玩家把握距离和位置 。透视投影广泛用于 3D 游戏、虚拟现实VR和增强现实AR等场景能营造逼真空间感和深度感让玩家有身临其境的体验。如第一人称射击游戏通过透视投影呈现真实远近效果增强沉浸感。2. 移动旋转创建坦克实例将烟拖动到坦克上设置位置为0.6, 0, -0.94和-0.5, 0, -0.94坦克添加刚体组件坦克添加碰撞盒子设置位置为0, 0.95, 0大小为1.51, 1.71, 1.62注意碰撞盒子不能紧挨地面容易检测坦克与地面发生碰撞导致坦克无法移动。将坦克做成预制体创建脚本文件 Tank.cs添加脚本实现坦克的前后移动功能约束刚体部分轴位置冻结 Y 轴旋转冻结 X 和 Z 轴添加脚本实现坦克旋转功能2.1. Tank.csusingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;publicclassTank:MonoBehaviour{publicfloatmoveSpeed;publicfloatangularSpeed;privateRigidbodyrb;// Start is called before the first frame updatevoidStart(){rbGetComponentRigidbody();}// Update is called once per framevoidUpdate(){}privatevoidFixedUpdate(){Move();}/// summary/// 移动/// /summaryvoidMove(){floatvInput.GetAxis(Vertical);floathInput.GetAxis(Horizontal);rb.velocitytransform.forward*v*moveSpeed;rb.angularVelocitytransform.up*h*angularSpeed;}}3. 两个玩家控制进入输入设置复制 Horizontal 轴修改 Horizontal 控制按键复制 Vertical 轴修改 Vertical 控制按键修改代码实现通过编号区分不同的控制3.1. Tank.csusingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;publicclassTank:MonoBehaviour{publicfloatmoveSpeed;publicfloatangularSpeed;publicintplayerNum;privateRigidbodyrb;// Start is called before the first frame updatevoidStart(){rbGetComponentRigidbody();}// Update is called once per framevoidUpdate(){}privatevoidFixedUpdate(){Move();}/// summary/// 移动/// /summaryvoidMove(){floatvInput.GetAxis(VerticalPplayerNum);floathInput.GetAxis(HorizontalPplayerNum);rb.velocitytransform.forward*v*moveSpeed;rb.angularVelocitytransform.up*h*angularSpeed;}}4. 发射炮弹子弹、爆炸预设体发射位置脚本子弹预设体爆炸预设体4.1. PreShell.csusingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;publicclassPreShell:MonoBehaviour{publicfloatspeed2f;publicGameObjectpreShellExplosionGo;privateRigidbodyrb;// Start is called before the first frame updatevoidStart(){rbGetComponentRigidbody();rb.velocitytransform.forward*speed;}// Update is called once per framevoidUpdate(){}privatevoidOnCollisionEnter(Collisioncollision){GameObjectshellExplosionGoInstantiate(preShellExplosionGo,transform.position,transform.rotation);Destroy(gameObject);Destroy(shellExplosionGo.gameObject,1.5f);}}4.2. Tank.csusingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;publicclassTank:MonoBehaviour{publicfloatmoveSpeed;publicfloatangularSpeed;publicintplayerNum;publicKeyCodeattackKey;publicTransformshootPointTr;publicGameObjectpreShellGo;privateRigidbodyrb;// Start is called before the first frame updatevoidStart(){rbGetComponentRigidbody();attackKeyKeyCode.Space;}// Update is called once per framevoidUpdate(){if(Input.GetKeyDown(attackKey)){Shoot();}}privatevoidFixedUpdate(){Move();}/// summary/// 移动/// /summaryvoidMove(){floatvInput.GetAxis(VerticalPplayerNum);floathInput.GetAxis(HorizontalPplayerNum);rb.velocitytransform.forward*v*moveSpeed;rb.angularVelocitytransform.up*h*angularSpeed;}/// summary/// 攻击/// /summaryvoidShoot(){GameObjectshellGoInstantiate(preShellGo,shootPointTr.position,shootPointTr.rotation);//shellGo.GetComponentRigidbody().velocity shellGo.transform.forward * 5;}}5. 产生伤害5.1. PreShell.csusingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;publicclassPreShell:MonoBehaviour{publicfloatspeed2f;publicGameObjectpreShellExplosionGo;privateRigidbodyrb;// Start is called before the first frame updatevoidStart(){rbGetComponentRigidbody();rb.velocitytransform.forward*speed;}// Update is called once per framevoidUpdate(){}privatevoidOnCollisionEnter(Collisioncollision){GameObjectshellExplosionGoInstantiate(preShellExplosionGo,transform.position,transform.rotation);Destroy(gameObject);Destroy(shellExplosionGo.gameObject,1.5f);//造成伤害Tanktankcollision.gameObject.GetComponentTank();if(tanknull)return;tank.currentBlood-10;//死亡if(tank.currentBlood0){tank.currentBlood0;Destroy(collision.gameObject);}}}5.2. Tank.csusingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;publicclassTank:MonoBehaviour{publicfloatmoveSpeed;publicfloatangularSpeed;publicintplayerNum;publicintcurrentBlood;publicintmaxBlood100;publicKeyCodeattackKey;publicTransformshootPointTr;publicGameObjectpreShellGo;privateRigidbodyrb;// Start is called before the first frame updatevoidStart(){rbGetComponentRigidbody();attackKeyKeyCode.Space;currentBloodmaxBlood;}// Update is called once per framevoidUpdate(){if(playerNum1Input.GetKeyDown(attackKey)){Shoot();}elseif(playerNum2Input.GetKeyDown(KeyCode.Keypad9)){Shoot();}}privatevoidFixedUpdate(){Move();}/// summary/// 移动/// /summaryvoidMove(){floatvInput.GetAxis(VerticalPplayerNum);floathInput.GetAxis(HorizontalPplayerNum);rb.velocitytransform.forward*v*moveSpeed;rb.angularVelocitytransform.up*h*angularSpeed;}/// summary/// 攻击/// /summaryvoidShoot(){GameObjectshellGoInstantiate(preShellGo,shootPointTr.position,shootPointTr.rotation);//shellGo.GetComponentRigidbody().velocity shellGo.transform.forward * 5;}}6. 摄像机跟随坦克6.1. MainCamera.csusingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;publicclassMainCamera:MonoBehaviour{publicTransformtank1;// 第一辆坦克的TransformpublicTransformtank2;// 第二辆坦克的TransformprivateVector3offset;// 摄像机相对于两辆坦克中心的偏移量privateCameramainCamera;// 主摄像机组件privatefloatdistance;// 两辆坦克之间的距离privatefloatcameraSize;// 正交摄像机的尺寸// Start is called before the first frame updatevoidStart(){// 检查是否正确赋值了两个坦克的Transformif(tank1null||tank2null)return;// 计算摄像机的初始偏移量Vector3tanksCenter(tank1.positiontank2.position)/2;offsettransform.position-tanksCenter;// 获取主摄像机组件mainCameraGetComponentCamera();}// Update is called once per framevoidUpdate(){// 如果任意一个坦克不存在则直接返回if(tank1null||tank2null)return;// 更新摄像机的位置Vector3tanksCenter(tank1.positiontank2.position)/2;transform.positiontanksCenteroffset;// 计算两辆坦克之间的距离distanceVector3.Distance(tank1.position,tank2.position);// 根据距离调整摄像机的正交尺寸cameraSizedistance*0.875f;mainCamera.orthographicSizecameraSize;}}7. 添加血条7.1. 设置血条物体新增血条物体设置 Canvas设置 Slider设置 Background设置 Fill7.2. 编写代码7.2.1. PreShell.csusingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;publicclassPreShell:MonoBehaviour{publicfloatspeed5f;//速度publicintdamage10;//伤害值publicGameObjectpreShellExplosionGo;//爆炸预设体对象privateRigidbodyrb;//刚体// Start is called before the first frame updatevoidStart(){rbGetComponentRigidbody();rb.velocitytransform.forward*speed;}// Update is called once per framevoidUpdate(){}/// summary/// 碰撞则产生爆炸并自我销毁/// /summary/// param namecollision/paramprivatevoidOnCollisionEnter(Collisioncollision){GameObjectshellExplosionGoInstantiate(preShellExplosionGo,transform.position,transform.rotation);//生成爆炸效果Destroy(gameObject);//销毁炮弹Destroy(shellExplosionGo,1.5f);//销毁爆炸效果Tanktankcollision.gameObject.GetComponentTank();if(tank!null){tank.currentBlood-damage;//造成了伤害tank.hpSlider.value(float)tank.currentBlood/tank.maxBlood;//更新血量滑动条if(tank.currentBlood0)Destroy(collision.gameObject);//销毁坦克}}}7.2.2. Tank.csusingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;usingUnityEngine.UI;publicclassTank:MonoBehaviour{publicfloatmoveSpeed5f;//移动速度publicfloatangularSpeed2f;//旋转角度publicintplayerNum1;//玩家编号publicintcurrentBlood;//当前血量publicintmaxBlood100;//最大血量publicGameObjectpreShellGo;//炮弹预设游戏对象publicSliderhpSlider;//血量滑动条privateTransformshootPoint;//发射位置privateRigidbodyrb;//刚体// Start is called before the first frame updatevoidStart(){currentBloodmaxBlood;rbGetComponentRigidbody();shootPointtransform.Find(ShootPoint);}// Update is called once per framevoidUpdate(){//如果按下空格键则发射炮弹if(playerNum1Input.GetKeyDown(KeyCode.Space)){Shoot();}elseif(playerNum2Input.GetKeyDown(KeyCode.P)){Shoot();}}privatevoidFixedUpdate(){Move();}/// summary/// 移动/// /summaryprivatevoidMove(){floatvInput.GetAxis(VerticalPplayerNum);floathInput.GetAxis(HorizontalPplayerNum);rb.velocitytransform.forward*v*moveSpeed;//前后移动rb.angularVelocitytransform.up*h*angularSpeed;//左右旋转}/// summary/// 发射炮弹/// /summaryprivatevoidShoot(){Instantiate(preShellGo,shootPoint.position,shootPoint.rotation);}}7.2.3. MainCamera.csusingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;publicclassMainCamera:MonoBehaviour{publicTransformtank1;// 第一辆坦克的TransformpublicTransformtank2;// 第二辆坦克的TransformprivateVector3offset;// 摄像机相对于两辆坦克中心的偏移量privateCameramainCamera;// 主摄像机组件privatefloatdistance;// 两辆坦克之间的距离privatefloatcameraSize;// 正交摄像机的尺寸// Start is called before the first frame updatevoidStart(){// 检查是否正确赋值了两个坦克的Transformif(tank1null||tank2null)return;// 计算摄像机的初始偏移量Vector3tanksCenter(tank1.positiontank2.position)/2;offsettransform.position-tanksCenter;// 获取主摄像机组件mainCameraGetComponentCamera();}// Update is called once per framevoidUpdate(){// 如果任意一个坦克不存在则直接返回if(tank1null||tank2null)return;// 更新摄像机的位置Vector3tanksCenter(tank1.positiontank2.position)/2;transform.positiontanksCenteroffset;// 计算两辆坦克之间的距离distanceVector3.Distance(tank1.position,tank2.position);// 根据距离调整摄像机的正交尺寸cameraSizedistance*0.875f;mainCamera.orthographicSizecameraSize;}}7.3. 少量细节8. 音效8.1. 坦克静止、行驶音效调正摄像机位置靠近坦克使摄像机录制到坦克音效8.2. 坦克销毁音效8.3. 炮弹发射音效8.4. 炮弹爆炸音效8.5. 背景音乐
版权声明:本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!

宿迁宿豫网站建设三维建模

5分钟零基础上手:NocoDB数据导出实战指南(含CSV/JSON双格式) 【免费下载链接】nocodb nocodb/nocodb: 是一个基于 node.js 和 SQLite 数据库的开源 NoSQL 数据库,它提供了可视化的 Web 界面用于管理和操作数据库。适合用于构建简单…

张小明 2026/1/8 1:30:50 网站建设

个人主题网站廊坊seo排名扣费

第一章:Open-AutoGLM 任务执行日志查看与分析在 Open-AutoGLM 系统中,任务执行日志是排查异常、监控运行状态和优化流程的核心依据。通过合理分析日志内容,开发者能够快速定位模型推理失败、资源超限或调度延迟等问题。日志存储路径与结构 默…

张小明 2026/1/7 15:18:59 网站建设

织梦微信网站模板按月网站建设

iOS项目架构实战:构建高可用评论系统的最佳路径 【免费下载链接】iOSProject iOS project of collected some demos for iOS App, use Objective-C 项目地址: https://gitcode.com/gh_mirrors/io/iOSProject 在移动应用开发中,评论系统的实现往往…

张小明 2026/1/7 8:27:37 网站建设

可信网站认证是否必须做网易企业邮箱和个人邮箱的区别

第一章:Dify工作流可视化编辑的核心价值Dify 工作流的可视化编辑功能重新定义了 AI 应用开发的交互方式,将复杂的逻辑编排转化为直观的图形操作。开发者与非技术人员均可通过拖拽节点、连接流程线的方式快速构建智能应用,显著降低使用门槛。提…

张小明 2026/1/8 1:29:10 网站建设

平顶山 网站建设公司wordpress tml

字节跳动VINCIE-3B开源:3亿参数改写图像编辑范式,效率提升8倍 【免费下载链接】VINCIE-3B 项目地址: https://ai.gitcode.com/hf_mirrors/ByteDance-Seed/VINCIE-3B 导语 2025年7月,字节跳动正式开源3亿参数模型VINCIE-3B&#xff0…

张小明 2026/1/7 3:55:00 网站建设

怎么做买东西的网站做网站要先申请域名吗

FaceFusion能否实现跨种族人脸替换?肤色适配算法解析在数字内容创作日益多元的今天,人脸替换技术早已不再局限于同一个人种内部的“换脸娱乐”。从影视特效中还原历史人物形象,到虚拟试妆平台支持全球用户预览彩妆效果,再到隐私保…

张小明 2026/1/8 1:20:44 网站建设