经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 程序设计 » 游戏设计 » 查看文章
PacMan 01——地图的搭建
来源:cnblogs  作者:优梦创客  时间:2019/9/24 11:28:13  对本文有异议

版权申明:

  • 本文原创首发于以下网站:
  1. 博客园『优梦创客』的空间:https://www.cnblogs.com/raymondking123
  2. 优梦创客的官方博客:https://91make.top
  3. 优梦创客的游戏讲堂:https://91make.ke.qq.com
  4. 『优梦创客』的微信公众号:umaketop
  • 您可以自由转载,但必须加入完整的版权声明

地图的搭建

碰撞器放置

1.调整每一个Trigger的大小。
2.找到准确位置,但要把Trigger范围扩大0.5,防止触发误判

放入豆子

一个一个的手动放入太麻烦了,这里我们用脚本生成
1.先创建一个MapController空物体
2.在上面加上脚本
3.在地图上加入map标签

说明:在地图上每隔一段距离生成一个点,如果有墙壁的话消除豆子,为了防止意外情况,判定只有map标签才会消除豆子

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class map : MonoBehaviour {
  5. //坐标组件;
  6. public GameObject Map_HstartPulse;//生成豆子地图起始点
  7. public GameObject Map_HendPulse;//生成豆子竖向结束点
  8. public GameObject Map_WendPulse;//生成豆子横向结束点
  9. const int x= 1;
  10. //预制体
  11. public GameObject Pulses;//生成的豆子(普通)
  12. //地图状态器
  13. // Use this for initialization
  14. public bool isbeigover = false;//豆子是否生成完成
  15. void Start () {
  16. }
  17. // Update is called once per frame
  18. void Update ()
  19. {
  20. IsPulse();
  21. }
  22. public void IsPulse()//生成豆子的方法
  23. {
  24. if (isbeigover==false)
  25. {
  26. Debug.Log("制造完了");
  27. for (float y = Map_HstartPulse.transform.position.y-1; y > Map_HendPulse.transform.position.y; y--)
  28. {
  29. for (float x = Map_HstartPulse.transform.position.x+1; x < Map_WendPulse.transform.position.x; x++)
  30. {
  31. GameObject ss= Instantiate(Pulses, new Vector2(x, y), Quaternion.identity);
  32. }
  33. }
  34. isbeigover = true;
  35. }
  36. }
  37. }

判断豆子是否要消失,因为不能有豆子和墙壁重合

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class PacdotController : MonoBehaviour {
  5. // Use this for initialization
  6. void Start () {
  7. }
  8. // Update is called once per frame
  9. void Update () {
  10. }
  11. private void OnTriggerStay2D(Collider2D collision)
  12. {
  13. if (collision.gameObject.tag == "map")
  14. {
  15. //Debug.Log("aaa");
  16. Destroy(this.gameObject);
  17. }
  18. }
  19. }

效果如下

动画制作

原文链接:http://www.cnblogs.com/raymondking123/p/11576877.html

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号