パックマン01--マップ構築

著作権:

  • 次のWebサイトで始まるこの記事オリジナル:
  1. ブログパーク「優れた夢のメイカーズムーブメント」空間にします。https://www.cnblogs.com/raymondking123
  2. 優秀な夢メイカーズムーブメント公式ブログます。https://91make.top
  3. 優れたゲーム夢のメーカー文化講演します。https://91make.ke.qq.com
  4. マイクロチャンネル公衆数の「優秀な夢メイカーズムーブメント」:umaketop
  • あなたは転載は自由ですが、完全な著作権表示を含める必要があります

ビルドの地図

衝突配置

1トリガーのそれぞれのサイズを調整します。
2.正確な位置を見つけ、しかし誤ったトリガを防止するために、0.5トリガーの範囲を拡大します

豆を入れて

一つ一つが手作業であまりにも多くのトラブルに、ここでは、生成されたスクリプトを使用
最初の空のオブジェクトMapController作成1.
2.上記のスクリプトで追加
マップ上のマップのタグを追加3.

説明:すべての世代に壁がある場合ポイントは、その後、事故を防止するために、豆を排除する地図上のいくつかの距離は、それが決定されるだけマップラベルは、豆を排除します

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

結果は以下のとおりであります

アニメーション

おすすめ

転載: www.cnblogs.com/raymondking123/p/11576877.html