网站建设研究网站建设维护公司资质

张小明 2026/3/13 5:58:50
网站建设研究,网站建设维护公司资质,网站构建计划,wordpress微信公众号模板视频链接#xff1a; https://www.bilibili.com/video/BV1wT9rYZEKe?spm_id_from333.788.videopod.sectionsvd_source25b783f5f945c4507229e9dec657b5bb 本教程涉及到 Unity 常用组件、常用方法等核心知识点#xff0c;掌握本教程相关知识后你就就可以快速掌握一些 U…视频链接https://www.bilibili.com/video/BV1wT9rYZEKe?spm_id_from333.788.videopod.sectionsvd_source25b783f5f945c4507229e9dec657b5bb本教程涉及到 Unity 常用组件、常用方法等核心知识点掌握本教程相关知识后你就就可以快速掌握一些 Unity2D 常用组件了1.需求分析玩家通过点击屏幕上的向左、向右移动按钮控制红色小车左右移动避让黄色小车黄色小车在屏幕最上方随机生成后向下移动屏幕右上方分数跟随时间变化而变化红色小车与某一辆黄色小车碰撞则游戏结束弹出游戏结束界面游戏结束界面上有本局游戏分数以及重新开始的按钮2.代码实现2.1 创建项目目录Imags静态图片Prefabs预设物体Resources动态资源Audio音频Scenes场景Scripts脚本2.2 创建面板、小车、按钮等2.3 按钮控制红色小车左右移动创建游戏管理脚本 GameManager.csusingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;publicclassGameManager:MonoBehaviour{/// summary/// 游戏管理器实例/// /summarypublicstaticGameManagerinsta;/// summary/// 主界面/// /summarypublicMainPanelmainPanel;privatevoidAwake(){instathis;}// Start is called before the first frame updatevoidStart(){}// Update is called once per framevoidUpdate(){}}红色小车挂载脚本 RedCar.csusingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;publicclassRedCar:MonoBehaviour{/// summary/// 移动速度/// /summaryprivateintmoveSpeed100;/// summary/// 移动方向/// /summarypublicintmoveDirection0;// Start is called before the first frame updatevoidStart(){}// Update is called once per framevoidUpdate(){//屏幕范围内左右移动if(moveDirection-1transform.localPosition.x-490)return;if(moveDirection1transform.localPosition.x490)return;transform.localPositionnewVector3(moveDirection*moveSpeed*Time.deltaTime,0,0);}/// summary/// 碰撞显示结束界面/// /summary/// param namecollision/paramprivatevoidOnTriggerEnter2D(Collider2Dcollision){GameManager.insta.overPanel.ShowPanel();}}主界面挂载脚本 MainPanel.cs拖拽相应物体usingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;usingUnityEngine.UI;publicclassMainPanel:MonoBehaviour{/// summary/// 红色小车物体/// /summarypublicRedCarredCar;/// summary/// 分数文本/// /summarypublicTextscoreText;// Start is called before the first frame updatevoidStart(){}// Update is called once per framevoidUpdate(){}/// summary/// 点击按钮向左移动/// /summarypublicvoidOnLeftMoveClick(){redCar.moveDirection-1;}/// summary/// 点击按钮向右移动/// /summarypublicvoidOnRightMoveClick(){redCar.moveDirection1;}}2.4 黄色小车自动向下移动黄色小车挂载脚本 YellowCar.csusingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;publicclassYellowCar:MonoBehaviour{/// summary/// 移动速度/// /summaryprivateintmoveSpeed100;// Start is called before the first frame updatevoidStart(){}// Update is called once per framevoidUpdate(){transform.localPosition-newVector3(0,moveSpeed*Time.deltaTime,0);//向下移动if(transform.localPosition.y-1060)Destroy(gameObject);//如果移动到屏幕最底端则自动销毁}}2.5 红色小车与黄色小车碰撞则游戏结束红色小车挂载组件 Box Collider 2D 和 Rigidbody 2D黄色小车挂载组件 Box Collider 2D结束界面挂载脚本 OverPanel.csusingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;usingUnityEngine.SceneManagement;usingUnityEngine.UI;publicclassOverPanel:MonoBehaviour{/// summary/// 分数文本/// /summarypublicTextscoreText;// Start is called before the first frame updatevoidStart(){}// Update is called once per framevoidUpdate(){}/// summary/// 显示面板/// /summarypublicvoidShowPanel(){Time.timeScale0f;//游戏暂停gameObject.SetActive(true);}/// summary/// 点击按钮重新开始游戏/// /summarypublicvoidOnRestartClick(){Time.timeScale1f;//游戏恢复gameObject.SetActive(false);SceneManager.LoadScene(0);}}GameManager.cs 新增结束界面变量publicclassGameManager:MonoBehaviour{/// summary/// 游戏管理器实例/// /summarypublicstaticGameManagerinsta;/// summary/// 主界面/// /summarypublicMainPanelmainPanel;/// summary/// 结束界面/// /summarypublicOverPaneloverPanel;...2.6 更新界面分数主界面...publicclassMainPanel:MonoBehaviour{/// summary/// 红色小车物体/// /summarypublicRedCarredCar;/// summary/// 分数文本/// /summarypublicTextscoreText;/// summary/// 分数数值/// /summarypublicintscore;/// summary/// 开始时间/// /summaryprivatefloatstartTime;// Start is called before the first frame updatevoidStart(){startTimeTime.time;}// Update is called once per framevoidUpdate(){//更新分数score(int)(Time.time-startTime);scoreText.text分数score;}...结束界面...publicclassOverPanel:MonoBehaviour{/// summary/// 分数文本/// /summarypublicTextscoreText;// Start is called before the first frame updatevoidStart(){}// Update is called once per framevoidUpdate(){scoreText.text分数GameManager.insta.mainPanel.score;}...2.7 通过预设随机生成黄色小车创建黄色小车根目录.../// summary/// 创建黄色小车上一次时间/// /summaryprivatefloatlastTime;/// summary/// 黄色小车物体预设/// /summarypublicGameObjectpreYellowCarGo;/// summary/// 黄色小车根目录/// /summarypublicGameObjectyellowCarRootGo;// Start is called before the first frame updatevoidStart(){startTimeTime.time;lastTimeTime.time;}// Update is called once per framevoidUpdate(){//更新分数score(int)(Time.time-startTime);scoreText.text分数score;//每过3秒生成一辆黄色小车if(Time.time-lastTime3f){CreateYellowCar();lastTimeTime.time;}}/// summary/// 点击按钮向左移动/// /summarypublicvoidOnLeftMoveClick(){redCar.moveDirection-1;}/// summary/// 点击按钮向右移动/// /summarypublicvoidOnRightMoveClick(){redCar.moveDirection1;}/// summary/// 创建黄色小车/// /summaryprivatevoidCreateYellowCar(){//在x坐标为-490到490之间随机生成黄色小车GameObjectyellowCarGoInstantiate(preYellowCarGo,yellowCarRootGo.transform);intrandomIntRandom.Range(-490,490);yellowCarGo.transform.localPositionnewVector3(randomInt,1060,0);}}2.8 添加音频创建游戏中音频物体.../// summary/// 黄色小车根目录/// /summarypublicGameObjectyellowCarRootGo;/// summary/// 游戏进行中音频/// /summarypublicAudioSourcegameInAudioSource;// Start is called before the first frame updatevoidStart(){startTimeTime.time;// 开始时间赋值lastTimeTime.time;// 创建黄色小车上一次时间赋值gameInAudioSource.Play();//播放游戏进行音乐}...创建游戏结束音频物体.../// summary/// 游戏技术音频/// /summarypublicAudioSourcegameOverAudioSource;.../// summary/// 显示面板/// /summarypublicvoidShowPanel(){Time.timeScale0f;//游戏暂停gameObject.SetActive(true);//停止游戏进行音频播放游戏结束音频if(GameManager.insta.mainPanel.gameInAudioSource.isPlaying){GameManager.insta.mainPanel.gameInAudioSource.Stop();}gameOverAudioSource.Play();}...2.9 物体换皮3.完整代码GameManagerusingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;publicclassGameManager:MonoBehaviour{/// summary/// 游戏管理器实例/// /summarypublicstaticGameManagerinsta;/// summary/// 主界面/// /summarypublicMainPanelmainPanel;/// summary/// 结束界面/// /summarypublicOverPaneloverPanel;privatevoidAwake(){instathis;}// Start is called before the first frame updatevoidStart(){}// Update is called once per framevoidUpdate(){}}MainPanelusingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;usingUnityEngine.UI;publicclassMainPanel:MonoBehaviour{/// summary/// 红色小车物体/// /summarypublicRedCarredCar;/// summary/// 分数文本/// /summarypublicTextscoreText;/// summary/// 分数数值/// /summarypublicintscore;/// summary/// 开始时间/// /summaryprivatefloatstartTime;/// summary/// 创建黄色小车上一次时间/// /summaryprivatefloatlastTime;/// summary/// 黄色小车物体预设/// /summarypublicGameObjectpreYellowCarGo;/// summary/// 黄色小车根目录/// /summarypublicGameObjectyellowCarRootGo;/// summary/// 游戏进行中音频/// /summarypublicAudioSourcegameInAudioSource;// Start is called before the first frame updatevoidStart(){startTimeTime.time;// 开始时间赋值lastTimeTime.time;// 创建黄色小车上一次时间赋值gameInAudioSource.Play();//播放游戏进行音乐}// Update is called once per framevoidUpdate(){//更新分数score(int)(Time.time-startTime);scoreText.text分数score;//每过3秒生成一辆黄色小车if(Time.time-lastTime3f){CreateYellowCar();lastTimeTime.time;}}/// summary/// 点击按钮向左移动/// /summarypublicvoidOnLeftMoveClick(){redCar.moveDirection-1;}/// summary/// 点击按钮向右移动/// /summarypublicvoidOnRightMoveClick(){redCar.moveDirection1;}/// summary/// 创建黄色小车/// /summaryprivatevoidCreateYellowCar(){//在x坐标为-490到490之间随机生成黄色小车GameObjectyellowCarGoInstantiate(preYellowCarGo,yellowCarRootGo.transform);intrandomIntRandom.Range(-490,490);yellowCarGo.transform.localPositionnewVector3(randomInt,1060,0);}}OverPanelusingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;usingUnityEngine.SceneManagement;usingUnityEngine.UI;publicclassOverPanel:MonoBehaviour{/// summary/// 分数文本/// /summarypublicTextscoreText;/// summary/// 游戏技术音频/// /summarypublicAudioSourcegameOverAudioSource;// Start is called before the first frame updatevoidStart(){}// Update is called once per framevoidUpdate(){scoreText.text分数GameManager.insta.mainPanel.score;}/// summary/// 显示面板/// /summarypublicvoidShowPanel(){Time.timeScale0f;//游戏暂停gameObject.SetActive(true);//停止游戏进行音频播放游戏结束音频if(GameManager.insta.mainPanel.gameInAudioSource.isPlaying){GameManager.insta.mainPanel.gameInAudioSource.Stop();}gameOverAudioSource.Play();}/// summary/// 点击按钮重新开始游戏/// /summarypublicvoidOnRestartClick(){Time.timeScale1f;//游戏恢复gameObject.SetActive(false);SceneManager.LoadScene(0);}}RedCarusingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;publicclassRedCar:MonoBehaviour{/// summary/// 移动速度/// /summaryprivateintmoveSpeed100;/// summary/// 移动方向/// /summarypublicintmoveDirection0;// Start is called before the first frame updatevoidStart(){}// Update is called once per framevoidUpdate(){//屏幕范围内左右移动if(moveDirection-1transform.localPosition.x-490)return;if(moveDirection1transform.localPosition.x490)return;transform.localPositionnewVector3(moveDirection*moveSpeed*Time.deltaTime,0,0);}/// summary/// 碰撞显示结束界面/// /summary/// param namecollision/paramprivatevoidOnTriggerEnter2D(Collider2Dcollision){GameManager.insta.overPanel.ShowPanel();}}YellowCarusingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;publicclassYellowCar:MonoBehaviour{/// summary/// 移动速度/// /summaryprivateintmoveSpeed100;// Start is called before the first frame updatevoidStart(){}// Update is called once per framevoidUpdate(){transform.localPosition-newVector3(0,moveSpeed*Time.deltaTime,0);//向下移动if(transform.localPosition.y-1060)Destroy(gameObject);//如果移动到屏幕最底端则自动销毁}}
版权声明:本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!

郑州手机端网站建设企业名录是什么

在人工智能模型参数规模持续攀升的今天,如何在保证性能的同时实现高效部署,成为行业面临的关键挑战。腾讯最新发布的混元4B指令微调模型GPTQ量化版(Hunyuan-4B-Instruct-GPTQ-Int4),以创新的4bit量化技术和深度优化的推…

张小明 2026/3/5 7:46:00 网站建设

做营销网站的企业优的网站建设

LangFlow工作流分享:10个可复用的大模型应用模板 在大模型技术席卷各行各业的今天,构建一个智能问答系统、自动化客服或知识管理助手,早已不再是只有资深AI工程师才能完成的任务。随着LangChain生态的成熟,越来越多开发者开始尝试…

张小明 2026/3/5 7:46:04 网站建设

门户网站优化报价东莞网站设计知名 乐云践新

博主介绍:✌全网粉丝10W,前互联网大厂软件研发、集结硕博英豪成立软件开发工作室,专注于计算机相关专业项目实战6年之久,累计开发项目作品上万套。凭借丰富的经验与专业实力,已帮助成千上万的学生顺利毕业,…

张小明 2026/3/5 7:46:04 网站建设

怎么做公司网站推广百度官网下载

本文详解如何自建GitLab代码仓库,配置CI/CD自动化流水线,打造完整的团队协作开发环境。前言 代码托管平台的选择: GitHub:开源首选,但私有仓库有限制Gitee:国内快,但有审查自建GitLab&#xff1…

张小明 2026/3/5 7:46:05 网站建设

vue做网站对seo怎么创建自己的网址

GPT5.2来了,三级模型矩阵精准戳中不同用户痛点。(图片源自网络,侵删)没有发布会,没有预热海报,12月12日凌晨,OpenAI突然扔出重磅炸弹——GPT-5.2系列模型低调上线,仅用一篇技术博客和…

张小明 2026/3/5 7:46:05 网站建设