第四章,实战 推箱子游戏

基于前三章的学习,本文档介绍了使用Unity制作推箱子游戏的详细过程。首先,通过地图关卡编辑器来创建不同关卡,接着实现游戏功能,包括玩家的滑动控制、射线检测判断推箱子逻辑,以及箱子、洞的简单脚本处理。最后,简述了游戏运行及UI界面的设计。
摘要由CSDN通过智能技术生成

有了前面三章的学习,我们试着做一个小游戏来强化学习的技术,比如做一个 推箱子Sokoban 游戏;

一.由于每关地图不一样,首先得想到的是做一个地图关卡编辑器

(很多类容都要用到前一章知识:

https://blog.csdn.net/mww584161068/article/details/79986005)

(由于没有美工给图,随便将就用点图,以实现功能为主)

 1,把图都做成预制体。

    

2.然后编辑需要加载这些预制体的脚本

(借助前一章的一些脚本,就不贴了

https://blog.csdn.net/mww584161068/article/details/79986005)

public class MapEditor :ViewEditor {

    static int selectMum;

    static int widthMum=1;
    static int heightMum=1;

    GameObject wallH;
    GameObject wallV;
    GameObject leftUp;
    GameObject rightUp;
    GameObject rightDown;
    GameObject leftDown;

    GameObject light;
    GameObject dark;


    protected override void OnGUI()
    {
        if (MwwWindow.instance != null)
        {
            selectMum = MwwWindow.instance.DrawViewSelect<MapEditor>(selectMum);

            EditorGUILayout.Space();
      
            widthMum = EditorGUILayout.IntField("宽度:", widthMum);
            heightMum = EditorGUILayout.IntField("高度:", heightMum);
            EditorGUILayout.Space();
            EditorGUILayout.Space();

            if (GUILayout.Button("生成边框"))
            {
                Create();
            }
        }
    }

    void Init()
    {
        wallH= (GameObject)Resources.Load("Prefab/H", typeof(GameObject));
        wallV = (GameObject)Resources.Load("Prefab/V", typeof(GameObject));
        leftUp= (GameObject)Resources.Load("Prefab/left_up", typeof(GameObject));
        rightUp= (GameObject)Resources.Load("Prefab/right_up", typeof(GameObject));
        rightDown = (GameObject)Resources.Load("Prefab/right_down", typeof(GameObject));
        leftDown= (GameObject)Resources.Load("Prefab/left_down", typeof(GameObject));

        light = (GameObject)Resources.Load("Prefab/light", typeof(GameObject));
        dark = (GameObject)Resources.Load("Prefab/dark", typeof(GameObject));
    }

    const float leftUp_wallH_V = 0.03f;

    const float leftUp_wallH=0.59f;
    const float 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值