Unity仿制经典像素游戏笨鸟先飞
Unity仿制经典像素游戏笨鸟先飞
一、场景搭建
- 新建一个场景,并导入素材
- 导入天空,并调整图层顺序
- 导入水管素材
二、像素鸟的搭建
- 添加小鸟对象
- 为小鸟添加2D刚体,并修改其重力为0.7
- 新建脚本
SportCtrl
,并添加以下代码
Rigidbody2D rb;
void Start()
{rb = GetComponent<Rigidbody2D>();
}void FixedUpdate()
{Fly();
}public void Fly()
{float xSpeed = 1f;Vector3 v = rb.velocity;float ySpeed = v.y;if (Input.GetMouseButton(0)){ySpeed = 2f;}rb.velocity = new Vector2(xSpeed, ySpeed);
}
- 为小鸟添加2D碰撞器
- 为地面和管子添加盒型碰撞器
无尽模式
- 新建脚本
CamCtrl
,添加以下代码
public Transform target;Vector3 offset;void Start(){offset = transform.position - target.position;}void LateUpdate(){transform.position = target.position + offset;}
- 将脚本挂载到相机上,并为Target赋值
- 限制相机的高度,修改Update方法为
Vector3 pos = target.position + offset;if (pos.y > 0.9)pos.y = 0.9f;else if (pos.y < -0.9)pos.y = -0.9f;transform.position = pos;
- 新建脚本
Endless
,并添加以下代码
public float distance;
void OnBecameInvisible()
{transform.Translate(Vector3.right* distance * 3);
}
- 挂载脚本
Endless
到地面、水管和天空上,并设置Distance
游戏UI
- 新建画布StartWnd,创建开始界面
- 新建画布ReadyWnd,添加素材
- 创建新的脚本
GameRoot
,添加以下代码
public static GameRoot Instance;public const int GAMESTART = 0;public const int GAMEREADY = 1;public const int GAMERUN = 2;public const int GAMEEND = 3;public int GAMESTATE = GAMESTART;public Transform StartWnd, ReadyWnd, EndWnd, bird;public Text txtScore;public int score = 0;void Start(){Instance = this;}public void Enter(){StartWnd.gameObject.SetActive(true);GAMESTATE = GAMESTART;}public void Ready(){bird.position = Vector3.zero;StartWnd.gameObject.SetActive(false);ReadyWnd.gameObject.SetActive(true);GAMESTATE = GAMEREADY;bird.rotation = Quaternion.identity;}public void Run(){ReadyWnd.gameObject.SetActive(false);GAMESTATE = GAMERUN;}public void End(){EndWnd.gameObject.SetActive(true);GAMESTATE = GAMEEND;}
- 创建脚本
StartWnd
,添加以下代码
public Button btnStart;// Use this for initializationvoid Start(){btnStart.onClick.AddListener(OnStartClick);}void OnStartClick(){GameRoot.Instance.Ready();}
- 新建脚本
ReadyWnd
,添加以下代码
public Button page1;public Transform page2;void Start(){page1.onClick.AddListener(OnClick);}void OnEnable(){page1.gameObject.SetActive(true);page2.gameObject.SetActive(false);}public void OnClick(){page1.gameObject.SetActive(false);page2.gameObject.SetActive(true);StartCoroutine(Run());}IEnumerator Run(){yield return new WaitForSeconds(1);GameRoot.Instance.Run();}
- 新建脚本
EndWnd
,添加以下代码
public Button page1;public Transform page2;public Button btnRestart;public Text txtScore, txtBest;// Use this for initializationvoid Start(){page1.onClick.AddListener(OnPage1Click);btnRestart.onClick.AddListener(OnRestartClick);}void OnEnable() {page1.gameObject.SetActive(true);page2.gameObject.SetActive(false);}// Update is called once per framevoid Update(){}void OnPage1Click(){page2.gameObject.SetActive(true);page1.gameObject.SetActive(false);txtBest.text = PlayerPrefs.GetInt("best").ToString();txtScore.text = GameRoot.Instance.score.ToString();}void OnRestartClick(){gameObject.SetActive(false);GameRoot.Instance.Ready();}
- 添加2d碰撞器
- 在
GameRoot
添加以下方法
public void GetPoint(){score++;txtScore.text = "Score:" + score;}
Unity仿制经典像素游戏笨鸟先飞相关推荐
- 【Unity2D】使用Unity制作2D像素游戏用到的使用插件
建议大家能够熟练使用这些软件后,再决定买正版. 接触的这些个软件,都是只能对单个精灵进行变化. 不支持纸娃娃, 精灵变色的插件 2DxFX Sprite Color FX 2D像素特效 这些个特效插件 ...
- c语言小程序飞机大战,飞机大战微信小游戏:经典像素飞机大战小程序,点开即玩...
50000+游戏爱好者已加入我们! 每天推荐好玩游戏! 关注我们,沐沐带你发现好游戏! <经典像素飞机大战>游戏小程序好玩吗? <经典像素飞机大战>小游戏怎么玩? 怎么进入&l ...
- 像素游戏的动态光影效果
动态光影 Dynamic lighting and shadows,动态光影 - 这在 3D 游戏中根本不算个事儿.可是,当想要在像素游戏中实现的时候,就没那么简单了,我们之前报道过 Sprite L ...
- [安全攻防进阶篇] 一.什么是逆向分析、逆向分析应用及经典扫雷游戏逆向
从2019年7月开始,我来到了一个陌生的专业--网络空间安全.初入安全领域,是非常痛苦和难受的,要学的东西太多.涉及面太广,但好在自己通过分享100篇"网络安全自学"系列文章,艰难 ...
- unity3d实现像素游戏的精确碰撞判定
-- 检测碰撞物,如果发生碰撞则进行位移 function LColliderBDY:BDYFixedUpdate(velocity)local isGround = falselocal isWal ...
- 基于Unity的2D小游戏 SpeedDown 开发笔记(学习bilibili@[M_Studio]的教学视频
基于Unity的2D小游戏 SpeedDown 开发笔记(学习bilibili@M_Studio的教学视频) 主要内容:在Sunnyland游戏的设计基础上,新增了物理组件Joint系列.DrawGi ...
- 从像素之间谈起:像素游戏的画面增强
转自:http://fushigi-hako.site/2017/07/02/from_pixel_to_screen_1/ 无所不在的像素画 分类 随着分辨率的普遍提高,我们已经告别了依赖于简陋像素 ...
- c语言见缝插针小游戏,Unity实现见缝插针小游戏
本文实例为大家分享了Unity实现见缝插针游戏的具体代码,供大家参考,具体内容如下 控制小球旋转 using System.Collections; using System.Collections. ...
- unity mega_[MEGA DEAL] Unity A至Z游戏开发套件(96%折扣)
unity mega 涵盖游戏开发的所有方面(83小时!),从Unity中的编码到在Blender中设计3D资产 嘿,怪胎, 本周,在我们的JCG Deals商店中 ,我们提供了另一个超值优惠 . 我 ...
最新文章
- 10道C++输出易错笔试题收集(敢进来挑战吗?)
- jquery PHP 中文乱码,PHP输出中文乱码怎么解决?
- 分享丨10年DBA老司机整理的Oracle学习路线图
- Ozon Tech Challenge 2020 (Div.1 + Div.2) E.Kuroni and the Score Distribution 构造
- Ubuntu上安装Samba服务器实现家庭共享
- vue入门:v-bind:class
- linux 中 man 1 man2 man3 ......man N的区别
- linux上mysql卸数_Linux下MySQL卸载和安装图文教程
- linux oracle异常处理,Oracle SQL 异常处理
- 老婆给我推荐了一个副业,现在收入高于我工资,我要不要辞职?
- 莫队--2038: [2009国家集训队]小Z的袜子(hose)
- PJzhang:python快速搭建局域网文件共享服务器
- excel表格乱码怎么解决呢?
- veeam备份linux,VeeamBackup Replication 创建备份任务
- 陈佼每周一蛋疼:“哼唱搜索”更像是个玩具
- 计算机老出现安全警报怎么办,windows安全警报怎么关闭,教您怎么关闭windows安全警报...
- 计算机里面的Profile怎么翻译比较好?
- matlab 函数pdf怎么用_PDF文档怎么进行批量旋转?调整页面用迅捷PDF转换器
- 嵩山少林寺网站向全世界公布了千年武功秘籍
- 【自存代码】划分数据集为训练集和测试集