Unity仿制经典像素游戏笨鸟先飞

一、场景搭建

  1. 新建一个场景,并导入素材
  2. 导入天空,并调整图层顺序
  3. 导入水管素材

二、像素鸟的搭建

  1. 添加小鸟对象
  2. 为小鸟添加2D刚体,并修改其重力为0.7
  3. 新建脚本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);
}
  1. 为小鸟添加2D碰撞器
  2. 为地面和管子添加盒型碰撞器

无尽模式

  1. 新建脚本CamCtrl,添加以下代码
 public Transform target;Vector3 offset;void Start(){offset = transform.position - target.position;}void LateUpdate(){transform.position = target.position + offset;}
  1. 将脚本挂载到相机上,并为Target赋值
  2. 限制相机的高度,修改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;
  1. 新建脚本Endless,并添加以下代码
public float distance;
void OnBecameInvisible()
{transform.Translate(Vector3.right* distance * 3);
}
  1. 挂载脚本Endless到地面、水管和天空上,并设置Distance

游戏UI

  1. 新建画布StartWnd,创建开始界面
  2. 新建画布ReadyWnd,添加素材
  3. 创建新的脚本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;}
  1. 创建脚本StartWnd,添加以下代码
 public Button btnStart;// Use this for initializationvoid Start(){btnStart.onClick.AddListener(OnStartClick);}void OnStartClick(){GameRoot.Instance.Ready();}
  1. 新建脚本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();}
  1. 新建脚本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();}
  1. 添加2d碰撞器
  2. GameRoot添加以下方法
public void GetPoint(){score++;txtScore.text = "Score:" + score;}

Unity仿制经典像素游戏笨鸟先飞相关推荐

  1. 【Unity2D】使用Unity制作2D像素游戏用到的使用插件

    建议大家能够熟练使用这些软件后,再决定买正版. 接触的这些个软件,都是只能对单个精灵进行变化. 不支持纸娃娃, 精灵变色的插件 2DxFX Sprite Color FX 2D像素特效 这些个特效插件 ...

  2. c语言小程序飞机大战,飞机大战微信小游戏:经典像素飞机大战小程序,点开即玩...

    50000+游戏爱好者已加入我们! 每天推荐好玩游戏! 关注我们,沐沐带你发现好游戏! <经典像素飞机大战>游戏小程序好玩吗? <经典像素飞机大战>小游戏怎么玩? 怎么进入&l ...

  3. 像素游戏的动态光影效果

    动态光影 Dynamic lighting and shadows,动态光影 - 这在 3D 游戏中根本不算个事儿.可是,当想要在像素游戏中实现的时候,就没那么简单了,我们之前报道过 Sprite L ...

  4. [安全攻防进阶篇] 一.什么是逆向分析、逆向分析应用及经典扫雷游戏逆向

    从2019年7月开始,我来到了一个陌生的专业--网络空间安全.初入安全领域,是非常痛苦和难受的,要学的东西太多.涉及面太广,但好在自己通过分享100篇"网络安全自学"系列文章,艰难 ...

  5. unity3d实现像素游戏的精确碰撞判定

    -- 检测碰撞物,如果发生碰撞则进行位移 function LColliderBDY:BDYFixedUpdate(velocity)local isGround = falselocal isWal ...

  6. 基于Unity的2D小游戏 SpeedDown 开发笔记(学习bilibili@[M_Studio]的教学视频

    基于Unity的2D小游戏 SpeedDown 开发笔记(学习bilibili@M_Studio的教学视频) 主要内容:在Sunnyland游戏的设计基础上,新增了物理组件Joint系列.DrawGi ...

  7. 从像素之间谈起:像素游戏的画面增强

    转自:http://fushigi-hako.site/2017/07/02/from_pixel_to_screen_1/ 无所不在的像素画 分类 随着分辨率的普遍提高,我们已经告别了依赖于简陋像素 ...

  8. c语言见缝插针小游戏,Unity实现见缝插针小游戏

    本文实例为大家分享了Unity实现见缝插针游戏的具体代码,供大家参考,具体内容如下 控制小球旋转 using System.Collections; using System.Collections. ...

  9. unity mega_[MEGA DEAL] Unity A至Z游戏开发套件(96%折扣)

    unity mega 涵盖游戏开发的所有方面(83小时!),从Unity中的编码到在Blender中设计3D资产 嘿,怪胎, 本周,在我们的JCG Deals商店中 ,我们提供了另一个超值优惠 . 我 ...

最新文章

  1. 10道C++输出易错笔试题收集(敢进来挑战吗?)
  2. jquery PHP 中文乱码,PHP输出中文乱码怎么解决?
  3. 分享丨10年DBA老司机整理的Oracle学习路线图
  4. Ozon Tech Challenge 2020 (Div.1 + Div.2) E.Kuroni and the Score Distribution 构造
  5. Ubuntu上安装Samba服务器实现家庭共享
  6. vue入门:v-bind:class
  7. linux 中 man 1 man2 man3 ......man N的区别
  8. linux上mysql卸数_Linux下MySQL卸载和安装图文教程
  9. linux oracle异常处理,Oracle SQL 异常处理
  10. 老婆给我推荐了一个副业,现在收入高于我工资,我要不要辞职?
  11. 莫队--2038: [2009国家集训队]小Z的袜子(hose)
  12. PJzhang:python快速搭建局域网文件共享服务器
  13. excel表格乱码怎么解决呢?
  14. veeam备份linux,VeeamBackup Replication 创建备份任务
  15. 陈佼每周一蛋疼:“哼唱搜索”更像是个玩具
  16. 计算机老出现安全警报怎么办,windows安全警报怎么关闭,教您怎么关闭windows安全警报...
  17. 计算机里面的Profile怎么翻译比较好?
  18. matlab 函数pdf怎么用_PDF文档怎么进行批量旋转?调整页面用迅捷PDF转换器
  19. 嵩山少林寺网站向全世界公布了千年武功秘籍
  20. 【自存代码】划分数据集为训练集和测试集

热门文章

  1. pdf文档怎么转换成excel?分享这几个方法!
  2. mysql排序convert_MYSQLVARCHAR排序CAST,CONVERT函数类型转换
  3. 网络教育风生水起,9158如何脱颖而出?
  4. 抵在心口的痛主角秦雪严朗by游泳的猫咪大结局免费在线阅读
  5. 获取用户Ip地址常见安全隐患及解决办法
  6. JS 文件上传/下载
  7. 如何为LumaQQ添加聊天机器人
  8. Broadcom WICED Wi-Fi 研究BCM943362WCD4之初始化
  9. 面试官的犀利问题是为了知道这些
  10. 贪心---圣诞老人的礼物