PacMan 01——地图的搭建

版权申明:

  • 本文原创首发于以下网站:
  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标签才会消除豆子

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class map : MonoBehaviour {
    //坐标组件;
    public GameObject Map_HstartPulse;//生成豆子地图起始点
    public GameObject Map_HendPulse;//生成豆子竖向结束点
    public GameObject Map_WendPulse;//生成豆子横向结束点
    const int x= 1;
    //预制体
    public GameObject Pulses;//生成的豆子(普通)
    //地图状态器
    // Use this for initialization
    public bool isbeigover = false;//豆子是否生成完成
	void Start () {
		
	}
	
	// Update is called once per frame
	void Update ()
    {
        IsPulse();
    }
    public void IsPulse()//生成豆子的方法
    {
        if (isbeigover==false)
        {
            Debug.Log("制造完了");
            for (float y = Map_HstartPulse.transform.position.y-1; y > Map_HendPulse.transform.position.y; y--)
            {
                for (float x = Map_HstartPulse.transform.position.x+1; x < Map_WendPulse.transform.position.x; x++)
                {
                   GameObject ss= Instantiate(Pulses, new Vector2(x, y), Quaternion.identity);
                }            
            }
            isbeigover = true;
        }
    }
}


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

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PacdotController : MonoBehaviour {

	// Use this for initialization
	void Start () {
		
	}
	// Update is called once per frame
	void Update () {
		
	}
    private void OnTriggerStay2D(Collider2D collision)
    {
        if (collision.gameObject.tag == "map")
        {
            //Debug.Log("aaa");
            Destroy(this.gameObject);
        }
    }
}

效果如下

动画制作

posted @ 2019-09-24 10:28  优梦创客  阅读(1156)  评论(0编辑  收藏  举报