PacMan 01-- map building

Copyright notice:

  • This article Original starting in the following website:
  1. Blog Park "excellent dream maker culture" in space: https: //www.cnblogs.com/raymondking123
  2. Excellent dream maker culture official blog: https: //91make.top
  3. Excellent game dream maker culture lecture: https: //91make.ke.qq.com
  4. "Excellent dream maker culture" of micro-channel public number: umaketop
  • You are free to reprint, but must include the full copyright notice

Map of build

Collision placed

1. Adjust the size of each of Trigger.
2. Locate the exact position, but to expand the range of 0.5 Trigger, to prevent false triggering

Put beans

One by one manually into too much trouble, here we use the generated script
1. first create an empty object MapController
2. Add in the above script
3. Add the map tag on the map

Description: In every generation some distance on the map a point, if there is a wall, then eliminate beans, in order to prevent accidents, it is determined only map labels will eliminate beans

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;
        }
    }
}

Determine whether the beans to disappear, because they can not have beans and walls coincide

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);
        }
    }
}

Results are as follows

Animation

Guess you like

Origin www.cnblogs.com/raymondking123/p/11576877.html