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

效果如下

動畫制作


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM